@@ -240,7 +240,7 @@ function! s:AgentRequest(method, params, ...) dict abort
240240if has_key (self , ' initialization_pending' )
241241call add (self .initialization_pending, request)
242242else
243- call timer_start ( 0 ,{_ - > s: SendRequest( self , request) } )
243+ call copilot#util#Defer ( function ( ' s:SendRequest' ), self , request)
244244endif
245245return call (' s:SetUpRequest' , [self , s: id , a: method , params] + a: 000 )
246246endfunction
@@ -330,7 +330,7 @@ function! s:OnResponse(agent, response, ...) abort
330330endif
331331endfunction
332332
333- function ! s: OnErr (agent, line , ... ) abort
333+ function ! s: OnErr (agent, ch , line , ... ) abort
334334if ! has_key (a: agent , ' serverInfo' )
335335call copilot#logger#Bare (' <-! ' . a: line )
336336endif
@@ -348,7 +348,7 @@ function! s:OnExit(agent, code, ...) abort
348348for id in sort (keys (a: agent .requests),{a , b - > + a > + b })
349349call s: RejectRequest (remove (a: agent .requests, id),{' code' : code, ' message' : ' Agent exited' , ' data' :{' status' : a: code }})
350350endfor
351- call timer_start ( 0 ,{_ - > get (s: instances , a: agent .id) is # a: agent ? remove (s: instances , a: agent .id) :{} })
351+ call copilot#util#Defer ({ - > get (s: instances , a: agent .id) is # a: agent ? remove (s: instances , a: agent .id) :{} })
352352call copilot#logger#Info (' Agent exited with status ' . a: code )
353353endfunction
354354
@@ -532,7 +532,7 @@ function! s:InitializeResult(result, agent) abort
532532call s: AfterInitialize (a: result , a: agent )
533533call s: Send (a: agent ,{' method' : ' initialized' , ' params' :{}})
534534for request in remove (a: agent , ' initialization_pending' )
535- call timer_start ( 0 , function (' s:SendRequest' , [ a: agent , request]) )
535+ call copilot#util#Defer ( function (' s:SendRequest' ), a: agent , request)
536536endfor
537537endfunction
538538
@@ -646,9 +646,9 @@ function! copilot#agent#New(...) abort
646646\ ' stoponexit' : ' ' ,
647647\ ' in_mode' : ' lsp' ,
648648\ ' out_mode' : ' lsp' ,
649- \ ' out_cb' :{j , d - > timer_start ( 0 , function (' s:OnMessage' , [ instance, d ]) ) },
650- \ ' err_cb' : { j , d - > timer_start ( 0 , function (' s:OnErr' , [instance, d ])) } ,
651- \ ' exit_cb' :{j , d - > timer_start ( 0 , function (' s:OnExit' , [ instance, d ]) ) },
649+ \ ' out_cb' :{j , d - > copilot#util#Defer ( function (' s:OnMessage' ), instance, d ) },
650+ \ ' err_cb' : function (' s:OnErr' , [instance]) ,
651+ \ ' exit_cb' :{j , d - > copilot#util#Defer ( function (' s:OnExit' ), instance, d ) },
652652\ })
653653let instance.id = job_info (instance.job).process
654654let opts.capabilities = s: vim_capabilities
0 commit comments