@@ -2,7 +2,7 @@ scriptencoding utf-8
22
33let s: plugin_version = copilot#version#String ()
44
5- let s: error_exit = -1
5+ let s: error_exit = -32097
66
77let 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' )
3232endfunction
3333
3434function ! 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
176176function ! 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
180180endfunction
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
371378endfunction
372379
373380function ! 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]
505508endfunction
@@ -556,9 +559,9 @@ endfunction
556559
557560function ! 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
564567endfunction
@@ -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)
0 commit comments