1- if exists (' g:autoloaded_copilot_agent' )
2- finish
3- endif
4- let g: autoloaded_copilot_agent = 1
5-
61scriptencoding utf- 8
72
8- let s: plugin_version = ' 1.13 .0'
3+ let s: plugin_version = ' 1.14 .0'
94
105let s: error_exit = -1
116
@@ -86,7 +81,7 @@ function! s:RequestAwait() dict abort
8681 if has_key (self , ' result' )
8782 return self .result
8883 endif
89- throw ' copilot#agent( ' . self .error .code . ' ) : ' . self .error .message
84+ throw ' copilot#agent:E ' . self .error .code . ' : ' . self .error .message
9085endfunction
9186
9287function ! s: RequestAgent () dict abort
@@ -240,14 +235,14 @@ function! s:RequestCancel() dict abort
240235 return self
241236endfunction
242237
243- function ! s: DispatchMessage (agent, handler, id, params, ... ) abort
238+ function ! s: DispatchMessage (agent, method, handler, id, params, ... ) abort
244239 try
245240 let response = {' result' : call (a: handler , [a: params ])}
246241 if response.result is # 0
247242 let response.result = v: null
248243 endif
249244 catch
250- call copilot#logger#Exception ()
245+ call copilot#logger#Exception (' lsp.request. ' . a: method )
251246 let response = {' error' : {' code' : -32000 , ' message' : v: exception }}
252247 endtry
253248 if ! empty (a: id )
@@ -264,7 +259,7 @@ function! s:OnMessage(agent, body, ...) abort
264259 let id = get (request, ' id' , v: null )
265260 let params = get (request, ' params' , v: null )
266261 if has_key (a: agent .methods, request.method)
267- return s: DispatchMessage (a: agent , a: agent .methods[request.method], id, params)
262+ return s: DispatchMessage (a: agent , request.method, a: agent .methods[request.method], id, params)
268263 elseif ! empty (id)
269264 call s: Send (a: agent , {" id" : id, " error" : {" code" : -32700 , " message" : " Method not found: " . request.method}})
270265 endif
@@ -387,6 +382,13 @@ function! s:Command() abort
387382 if ! has (' nvim-0.6' ) && v: version < 900
388383 return [v: null , ' ' , ' Vim version too old' ]
389384 endif
385+ let agent = get (g: , ' copilot_agent_command' , ' ' )
386+ if empty (agent) || ! filereadable (agent)
387+ let agent = s: root . ' /dist/agent.js'
388+ if ! filereadable (agent)
389+ return [v: null , ' ' , ' Could not find dist/agent.js (bad install?)' ]
390+ endif
391+ endif
390392 let node = get (g: , ' copilot_node_command' , ' ' )
391393 if empty (node)
392394 let node = [' node' ]
@@ -400,9 +402,12 @@ function! s:Command() abort
400402 return [v: null , ' ' , ' Node.js executable `' . get (node, 0 , ' ' ) . " ' not found" ]
401403 endif
402404 endif
405+ if get (g: , ' copilot_ignore_node_version' )
406+ return [node + [agent, ' --stdio' ], ' ' , ' ' ]
407+ endif
403408 let node_version = s: GetNodeVersion (node)
404409 let warning = ' '
405- if ! get ( g: , ' copilot_ignore_node_version ' ) && node_version.major < 18 && get (node, 0 , ' ' ) !=# ' node' && executable (' node' )
410+ if node_version.major < 18 && get (node, 0 , ' ' ) !=# ' node' && executable (' node' )
406411 let node_version_from_path = s: GetNodeVersion ([' node' ])
407412 if node_version_from_path.major >= 18
408413 let warning = ' Ignoring g:copilot_node_command: Node.js ' . node_version.string . ' is end-of-life'
@@ -421,13 +426,6 @@ function! s:Command() abort
421426 return [v: null , node_version.string , ' Node.js version 18.x or newer required but found ' . node_version.string ]
422427 endif
423428 endif
424- let agent = get (g: , ' copilot_agent_command' , ' ' )
425- if empty (agent) || ! filereadable (agent)
426- let agent = s: root . ' /dist/agent.js'
427- if ! filereadable (agent)
428- return [v: null , node_version.string , ' Could not find dist/agent.js (bad install?)' ]
429- endif
430- endif
431429 return [node + [agent, ' --stdio' ], node_version.string , warning]
432430endfunction
433431
@@ -520,7 +518,9 @@ function! copilot#agent#New(...) abort
520518 let instance.node_version_warning = command_error
521519 endif
522520 endif
523- let instance.node_version = node_version
521+ if ! empty (node_version)
522+ let instance.node_version = node_version
523+ endif
524524 if has (' nvim' )
525525 call extend (instance, {
526526 \ ' Close' : function (' s:LspClose' ),
0 commit comments