Skip to content

Commit dfa657c

Browse files
committed
Copilot.vim 1.31.0
1 parent b603990 commit dfa657c

File tree

7 files changed

+562
-515
lines changed

7 files changed

+562
-515
lines changed

autoload/copilot.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ function! s:commands.version(opts) abort
726726
if exists('s:agent.serverInfo.version')
727727
echo s:agent.serverInfo.name . ' ' . s:agent.serverInfo.version
728728
else
729-
echo 'dist/agent.js ' . versions.Await().version
729+
echo 'GitHub Copilot Language Server ' . versions.Await().version
730730
endif
731731
if exists('s:agent.node_version')
732732
echo 'Node.js ' . s:agent.node_version

autoload/copilot/agent.vim

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ scriptencoding utf-8
22

33
let s:plugin_version = copilot#version#String()
44

5-
let s:error_exit = -1
5+
let s:error_exit = -32097
66

77
let s:root = expand('<sfile>:h:h:h')
88

@@ -22,13 +22,13 @@ function! s:VimClose() dict abort
2222
let job = self.job
2323
if has_key(self, 'kill')
2424
call job_stop(job, 'kill')
25-
call copilot#logger#Warn('Agent forcefully terminated')
25+
call copilot#logger#Warn('Process forcefully terminated')
2626
return
2727
endif
2828
let self.kill = v:true
2929
let self.shutdown = self.Request('shutdown', {}, function(self.Notify, ['exit']))
3030
call timer_start(2000, { _ -> job_stop(job, 'kill') })
31-
call copilot#logger#Debug('Agent shutdown initiated')
31+
call copilot#logger#Debug('Process shutdown initiated')
3232
endfunction
3333

3434
function! s:LogSend(request, line) abort
@@ -62,7 +62,7 @@ function! s:Send(agent, request) abort
6262
catch /^Vim\%((\a\+)\)\=:E906:/
6363
let a:agent.kill = v:true
6464
let job = a:agent.job
65-
call copilot#logger#Warn('Terminating agent after failed write')
65+
call copilot#logger#Warn('Terminating process after failed write')
6666
call job_stop(job)
6767
call timer_start(2000, { _ -> job_stop(job, 'kill') })
6868
return v:false
@@ -175,7 +175,7 @@ endfunction
175175

176176
function! s:SendRequest(agent, request, ...) abort
177177
if empty(s:Send(a:agent, a:request)) && has_key(a:request, 'id') && has_key(a:agent.requests, a:request.id)
178-
call s:RejectRequest(remove(a:agent.requests, a:request.id), {'code': 257, 'message': 'Write failed'})
178+
call s:RejectRequest(remove(a:agent.requests, a:request.id), {'code': -32099, 'message': 'Write failed'})
179179
endif
180180
endfunction
181181

@@ -362,12 +362,19 @@ function! s:OnExit(agent, code, ...) abort
362362
if has_key(a:agent, 'client_id')
363363
call remove(a:agent, 'client_id')
364364
endif
365-
let code = a:code < 0 || a:code > 255 ? 256 : a:code
365+
let error = {'code': s:error_exit, 'message': 'Process exited with status ' . a:code, 'data': {'status': a:code}}
366+
if a:code == 2
367+
let error.message = 'Process aborted due to unsupported Node.js version'
368+
endif
366369
for id in sort(keys(a:agent.requests), { a, b -> +a > +b })
367-
call s:RejectRequest(remove(a:agent.requests, id), {'code': code, 'message': 'Agent exited', 'data': {'status': a:code}})
370+
call s:RejectRequest(remove(a:agent.requests, id), deepcopy(error))
368371
endfor
369372
call copilot#util#Defer({ -> get(s:instances, a:agent.id) is# a:agent ? remove(s:instances, a:agent.id) : {} })
370-
call copilot#logger#Info('Agent exited with status ' . a:code)
373+
if a:code == 0
374+
call copilot#logger#Info(error.message)
375+
else
376+
call copilot#logger#Warn(error.message)
377+
endif
371378
endfunction
372379

373380
function! copilot#agent#LspInit(agent_id, initialize_result) abort
@@ -482,24 +489,20 @@ function! s:Command() abort
482489
endif
483490
let node_version = s:GetNodeVersion(node)
484491
let warning = ''
485-
if node_version.major < 18 && get(node, 0, '') !=# 'node' && executable('node')
486-
let node_version_from_path = s:GetNodeVersion(['node'])
487-
if node_version_from_path.major >= 18
488-
let warning = 'Ignoring g:copilot_node_command: Node.js ' . node_version.string . ' is end-of-life'
489-
let node = ['node']
490-
let node_version = node_version_from_path
491-
endif
492-
endif
493492
if node_version.status != 0
494493
return [v:null, '', 'Node.js exited with status ' . node_version.status]
495494
endif
496-
if !get(g:, 'copilot_ignore_node_version')
497-
if node_version.major == 0
498-
return [v:null, node_version.string, 'Could not determine Node.js version']
499-
elseif node_version.major < 16 || node_version.major == 16 && node_version.minor < 14 || node_version.major == 17 && node_version.minor < 3
500-
" 16.14+ and 17.3+ still work for now, but are end-of-life
501-
return [v:null, node_version.string, 'Node.js version 18.x or newer required but found ' . node_version.string]
502-
endif
495+
if get(node, 0, '') !=# 'node'
496+
let upgrade_advice = 'Change g:copilot_node_command to'
497+
else
498+
let upgrade_advice = 'Upgrade to'
499+
endif
500+
if node_version.major == 0
501+
return [v:null, node_version.string, 'Could not determine Node.js version']
502+
elseif node_version.major < 16 || node_version.major == 16 && node_version.minor < 14 || node_version.major == 17 && node_version.minor < 3
503+
return [v:null, node_version.string, 'Node.js ' . node_version.string . ' is unsupported. ' . upgrade_advice . ' 18.x or newer']
504+
elseif node_version.major < 18
505+
let warning = 'Node.js ' . node_version.string . ' support will soon be dropped. ' . upgrade_advice . ' 18.x or newer'
503506
endif
504507
return [node + agent + ['--stdio'], node_version.string, warning]
505508
endfunction
@@ -556,9 +559,9 @@ endfunction
556559

557560
function! s:InitializeError(error, agent) abort
558561
if a:error.code == s:error_exit
559-
let a:agent.startup_error = 'Agent exited with status ' . a:error.data.status
562+
let a:agent.startup_error = a:error.message
560563
else
561-
let a:agent.startup_error = 'Unexpected error ' . a:error.code . ' calling agent: ' . a:error.message
564+
let a:agent.startup_error = 'Unexpected error E' . a:error.code . ' initializing language server: ' . a:error.message
562565
call a:agent.Close()
563566
endif
564567
endfunction
@@ -630,7 +633,9 @@ function! copilot#agent#New(...) abort
630633
return instance
631634
else
632635
let instance.node_version_warning = command_error
633-
call copilot#logger#Warn(command_error)
636+
echohl WarningMsg
637+
echomsg 'Copilot: ' . command_error
638+
echohl NONE
634639
endif
635640
endif
636641
if !empty(node_version)

autoload/copilot/logger.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function! copilot#logger#Raw(level, message) abort
5151
endfunction
5252

5353
function! copilot#logger#Debug(...) abort
54-
if $COPILOT_AGENT_VERBOSE !~# '^\%(1\|true\)$'
54+
if empty(get(g:, 'copilot_debug'))
5555
return
5656
endif
5757
call copilot#logger#Raw(4, a:000)

autoload/copilot/version.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function! copilot#version#String() abort
2-
return '1.30.0'
2+
return '1.31.0'
33
endfunction

dist/agent.js

Lines changed: 524 additions & 482 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: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/copilot.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ scriptencoding utf-8
77

88
command! -bang -nargs=? -range=-1 -complete=customlist,copilot#CommandComplete Copilot exe copilot#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)
99

10-
if v:version < 800 || !exists('##CompleteChanged')
10+
if v:version < 800 || !exists('##InsertLeavePre')
1111
finish
1212
endif
1313

0 commit comments

Comments
 (0)