@@ -5,7 +5,7 @@ let g:autoloaded_copilot_agent = 1
55
66scriptencoding utf- 8
77
8- let s: plugin_version = ' 1.10.2 '
8+ let s: plugin_version = ' 1.10.3 '
99
1010let s: error_exit = -1
1111
@@ -391,6 +391,18 @@ function! copilot#agent#LspHandle(agent_id, response) abort
391391 call s: OnResponse (s: instances [a: agent_id ], a: response )
392392endfunction
393393
394+ function ! s: GetNodeVersion (command ) abort
395+ let out = []
396+ let err = []
397+ let status = copilot#job#Stream (a: command + [' --version' ], function (' add' , [out]), function (' add' , [err]))
398+ let string = matchstr (join (out, ' ' ), ' ^v\zs\d\+\.[^[:space:]]*' )
399+ if status != 0
400+ let string = ' '
401+ endif
402+ let major = str2nr (string )
403+ return {' status' : status, ' string' : string , ' major' : major}
404+ endfunction
405+
394406function ! s: Command () abort
395407 if ! has (' nvim-0.6' ) && v: version < 900
396408 return [v: null , ' ' , ' Vim version too old' ]
@@ -408,29 +420,34 @@ function! s:Command() abort
408420 return [v: null , ' ' , ' Node.js executable `' . get (node, 0 , ' ' ) . " ' not found" ]
409421 endif
410422 endif
411- let out = []
412- let err = []
413- let status = copilot#job#Stream (node + [' --version' ], function (' add' , [out]), function (' add' , [err]))
414- if status != 0
415- return [v: null , ' ' , ' Node.js exited with status ' . status]
423+ let node_version = s: GetNodeVersion (node)
424+ let warning = ' '
425+ if node_version.major < 18 && get (node, 0 , ' ' ) !=# ' node'
426+ let node_version_from_path = s: GetNodeVersion ([' node' ])
427+ if node_version_from_path.major >= 18
428+ let warning = ' Ignoring g:copilot_node_command: Node.js ' . node_version.string . ' is end-of-life'
429+ let node = [' node' ]
430+ let node_version = node_version_from_path
431+ endif
432+ endif
433+ if node_version.status != 0
434+ return [v: null , ' ' , ' Node.js exited with status ' . node_version.status]
416435 endif
417- let node_version = matchstr (join (out, ' ' ), ' ^v\zs\d\+\.[^[:space:]]*' )
418- let major = str2nr (node_version)
419436 if ! get (g: , ' copilot_ignore_node_version' )
420- if major == 0
421- return [v: null , node_version, ' Could not determine Node.js version' ]
422- elseif major < 16
423- return [v: null , node_version, ' Node.js version 16.x or newer required but found ' . node_version]
437+ if node_version. major == 0
438+ return [v: null , node_version. string , ' Could not determine Node.js version' ]
439+ elseif node_version. major < 16
440+ return [v: null , node_version. string , ' Node.js version 16.x or newer required but found ' . node_version. string ]
424441 endif
425442 endif
426443 let agent = get (g: , ' copilot_agent_command' , ' ' )
427444 if empty (agent) || ! filereadable (agent)
428445 let agent = s: root . ' /dist/agent.js'
429446 if ! filereadable (agent)
430- return [v: null , node_version, ' Could not find dist/agent.js (bad install?)' ]
447+ return [v: null , node_version. string , ' Could not find dist/agent.js (bad install?)' ]
431448 endif
432449 endif
433- return [node + [agent], node_version, ' ' ]
450+ return [node + [agent], node_version. string , warning ]
434451endfunction
435452
436453function ! s: UrlDecode (str) abort
@@ -475,6 +492,11 @@ function! s:GetCapabilitiesResult(result, agent) abort
475492 let a: agent .capabilities = get (a: result , ' capabilities' , {})
476493 let info = deepcopy (copilot#agent#EditorInfo ())
477494 let info.editorInfo.version .= ' + Node.js ' . a: agent .node_version
495+ if has_key (a: agent , ' node_version_warning' )
496+ let info.editorInfo.version .= ' (ignored g:copilot_node_command)'
497+ elseif ! empty (get (g: , ' copilot_node_command' , ' ' ))
498+ let info.editorInfo.version .= ' (used g:copilot_node_command)'
499+ endif
478500 call a: agent .Request (' setEditorInfo' , extend ({' editorConfiguration' : a: agent .editorConfiguration}, info))
479501endfunction
480502
@@ -513,9 +535,13 @@ function! copilot#agent#New(...) abort
513535 \ }
514536 let [command , node_version, command_error] = s: Command ()
515537 if len (command_error)
516- let instance.id = -1
517- let instance.startup_error = command_error
518- return instance
538+ if empty (command )
539+ let instance.id = -1
540+ let instance.startup_error = command_error
541+ return instance
542+ else
543+ let instance.node_version_warning = command_error
544+ endif
519545 endif
520546 let instance.node_version = node_version
521547 if has (' nvim' )
0 commit comments