@@ -72,7 +72,12 @@ function! s:Send(agent, request) abort
7272endfunction
7373
7474function ! s: AgentNotify (method, params) dict abort
75- return s: Send (self , {' method' : a: method , ' params' : a: params })
75+ let request = {' method' : a: method , ' params' : a: params }
76+ if has_key (self , ' initialization_pending' )
77+ call add (self .initialization_pending, request)
78+ else
79+ return s: Send (self , request)
80+ endif
7681endfunction
7782
7883function ! s: RequestWait () dict abort
@@ -164,8 +169,8 @@ function! s:BufferText(bufnr) abort
164169 return join (getbufline (a: bufnr , 1 , ' $' ), " \n " ) . " \n "
165170endfunction
166171
167- function ! s: SendRequest (agent, request) abort
168- if empty (s: Send (a: agent , a: request )) && has_key (a: agent .requests, a: request .id)
172+ function ! s: SendRequest (agent, request, ... ) abort
173+ if empty (s: Send (a: agent , a: request )) && has_key (a: request , ' id ' ) && has_key ( a: agent .requests, a: request .id)
169174 call s: RejectRequest (remove (a: agent .requests, a: request .id), {' code' : 257 , ' message' : ' Write failed' })
170175 endif
171176endfunction
@@ -524,15 +529,10 @@ function! s:AfterInitialize(result, agent) abort
524529endfunction
525530
526531function ! s: InitializeResult (result, agent) abort
527- let pending = get (a: agent , ' initialization_pending' , [])
528- if has_key (a: agent , ' initialization_pending' )
529- call remove (a: agent , ' initialization_pending' )
530- endif
531- call a: agent .Notify (' initialized' , {})
532532 call s: AfterInitialize (a: result , a: agent )
533- call a: agent. Notify ( ' workspace/didChangeConfiguration ' , {' settings ' : a: agent .settings })
534- for request in pending
535- call timer_start (0 , { _ - > s: SendRequest( a: agent , request) } )
533+ call s: Send ( a: agent , {' method ' : ' initialized ' , ' params ' : {} })
534+ for request in remove ( a: agent , ' initialization_pending ' )
535+ call timer_start (0 , function ( ' s:SendRequest' , [ a: agent , request]) )
536536 endfor
537537endfunction
538538
@@ -578,7 +578,6 @@ let s:vim_capabilities = {
578578function ! copilot#agent#New (... ) abort
579579 let opts = a: 0 ? a: 1 : {}
580580 let instance = {' requests' : {},
581- \ ' settings' : extend (copilot#agent#Settings (), get (opts, ' editorConfiguration' , {})),
582581 \ ' workspaceFolders' : {},
583582 \ ' Close' : function (' s:AgentClose' ),
584583 \ ' Notify' : function (' s:AgentNotify' ),
@@ -611,6 +610,7 @@ function! copilot#agent#New(...) abort
611610 \ ' editorPluginInfo' : copilot#agent#EditorPluginInfo (),
612611 \ }
613612 let opts.workspaceFolders = []
613+ let settings = extend (copilot#agent#Settings (), get (opts, ' editorConfiguration' , {}))
614614 if type (get (g: , ' copilot_workspace_folders' )) == v: t_list
615615 for folder in g: copilot_workspace_folders
616616 if type (folder) == v: t_string && ! empty (folder) && folder !~# ' \*\*\|^/$'
@@ -634,7 +634,7 @@ function! copilot#agent#New(...) abort
634634 \ ' Attach' : function (' s:NvimAttach' ),
635635 \ ' IsAttached' : function (' s:NvimIsAttached' ),
636636 \ })
637- let instance.client_id = eval (" v:lua.require'_copilot'.lsp_start_client(command, keys(instance.methods), opts, instance. settings)" )
637+ let instance.client_id = eval (" v:lua.require'_copilot'.lsp_start_client(command, keys(instance.methods), opts, settings)" )
638638 let instance.id = instance.client_id
639639 else
640640 let state = {' headers' : {}, ' mode' : ' headers' , ' buffer' : ' ' }
@@ -655,6 +655,7 @@ function! copilot#agent#New(...) abort
655655 let opts.processId = getpid ()
656656 let request = instance.Request (' initialize' , opts, function (' s:InitializeResult' ), function (' s:InitializeError' ), instance)
657657 let instance.initialization_pending = []
658+ call instance.Notify (' workspace/didChangeConfiguration' , {' settings' : settings})
658659 endif
659660 let s: instances [instance.id] = instance
660661 return instance
0 commit comments