@@ -2,7 +2,7 @@ scriptencoding utf-8
2
2
3
3
let s: plugin_version= copilot#version#String ()
4
4
5
- let s: error_exit= -1
5
+ let s: error_exit= -32097
6
6
7
7
let s: root= expand (' <sfile>:h:h:h' )
8
8
@@ -22,13 +22,13 @@ function! s:VimClose() dict abort
22
22
let job= self .job
23
23
if has_key (self ,' kill' )
24
24
call job_stop (job,' kill' )
25
- call copilot#logger#Warn (' Agent forcefully terminated' )
25
+ call copilot#logger#Warn (' Process forcefully terminated' )
26
26
return
27
27
endif
28
28
let self .kill= v: true
29
29
let self .shutdown= self .Request (' shutdown' , {},function (self .Notify, [' exit' ]))
30
30
call timer_start (2000 , { _- >job_stop (job,' kill' ) })
31
- call copilot#logger#Debug (' Agent shutdown initiated' )
31
+ call copilot#logger#Debug (' Process shutdown initiated' )
32
32
endfunction
33
33
34
34
function ! s: LogSend (request,line )abort
@@ -62,7 +62,7 @@ function! s:Send(agent, request) abort
62
62
catch /^Vim\%((\a\+)\)\=:E906:/
63
63
let a: agent .kill= v: true
64
64
let job= a: agent .job
65
- call copilot#logger#Warn (' Terminatingagent after failed write' )
65
+ call copilot#logger#Warn (' Terminatingprocess after failed write' )
66
66
call job_stop (job)
67
67
call timer_start (2000 , { _- >job_stop (job,' kill' ) })
68
68
return v: false
@@ -175,7 +175,7 @@ endfunction
175
175
176
176
function ! s: SendRequest (agent, request,... )abort
177
177
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' })
179
179
endif
180
180
endfunction
181
181
@@ -362,12 +362,19 @@ function! s:OnExit(agent, code, ...) abort
362
362
if has_key (a: agent ,' client_id' )
363
363
call remove (a: agent ,' client_id' )
364
364
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
366
369
for idin 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 ) )
368
371
endfor
369
372
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
371
378
endfunction
372
379
373
380
function ! copilot#agent#LspInit (agent_id, initialize_result)abort
@@ -482,24 +489,20 @@ function! s:Command() abort
482
489
endif
483
490
let node_version= s: GetNodeVersion (node)
484
491
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
493
492
if node_version.status!= 0
494
493
return [v: null ,' ' ,' Node.js exited with status' . node_version.status]
495
494
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'
503
506
endif
504
507
return [node+ agent+ [' --stdio' ], node_version.string , warning]
505
508
endfunction
@@ -556,9 +559,9 @@ endfunction
556
559
557
560
function ! s: InitializeError (error , agent)abort
558
561
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
560
563
else
561
- let a: agent .startup_error= ' Unexpected error' .a: error .code .' calling agent :' .a: error .message
564
+ let a: agent .startup_error= ' Unexpected errorE ' .a: error .code .' initializing language server :' .a: error .message
562
565
call a: agent .Close ()
563
566
endif
564
567
endfunction
@@ -630,7 +633,9 @@ function! copilot#agent#New(...) abort
630
633
return instance
631
634
else
632
635
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
634
639
endif
635
640
endif
636
641
if ! empty (node_version)