Skip to content

Commit 998cf5a

Browse files
committed
Copilot.vim 1.10.3
1 parent 719dd8d commit 998cf5a

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

autoload/copilot.vim

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ function! s:NodeVersionWarning() abort
9292
if exists('s:agent.node_version') && s:agent.node_version =~# '^16\.'
9393
echohl WarningMsg
9494
echo "Warning: Node.js 16 is approaching end of life and support will be dropped in a future release of copilot.vim."
95-
if get(g:, 'copilot_node_command', 'node') isnot# 'node'
96-
echo "g:copilot_node_command is set to a non-default value. Consider removing it from your" (has('nvim') ? 'Neovim' : 'Vim') "configuration."
97-
endif
95+
echohl NONE
96+
elseif exists('s:agent.node_version_warning')
97+
echohl WarningMsg
98+
echo 'Warning:' s:agent.node_version_warning
9899
echohl NONE
99100
endif
100101
endfunction
@@ -745,7 +746,7 @@ function! copilot#Command(line1, line2, range, bang, mods, arg) abort
745746
try
746747
let err = copilot#Agent().StartupError()
747748
if !empty(err)
748-
return 'echo ' . string('Copilot: ' . string(err))
749+
return 'echo ' . string('Copilot: ' . err)
749750
endif
750751
try
751752
let opts = copilot#Call('checkStatus', {'options': {'localChecksOnly': v:true}})

autoload/copilot/agent.vim

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let g:autoloaded_copilot_agent = 1
55

66
scriptencoding utf-8
77

8-
let s:plugin_version = '1.10.2'
8+
let s:plugin_version = '1.10.3'
99

1010
let 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)
392392
endfunction
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+
394406
function! 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]
434451
endfunction
435452

436453
function! 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))
479501
endfunction
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')

dist/agent.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/agent.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)