@@ -43,7 +43,7 @@ function! s:Running() abort
4343endfunction
4444
4545function ! s: Start () abort
46- if s: Running ()
46+ if s: Running () || exists ( ' s:client.startup_error ' )
4747 return
4848 endif
4949 let s: client = copilot#client#New ({' editorConfiguration' : s: EditorConfiguration ()})
@@ -70,11 +70,7 @@ function! copilot#RunningClient() abort
7070endfunction
7171
7272function ! s: NodeVersionWarning () abort
73- if exists (' s:client.node_version' ) && s: client .node_version = ~# ' ^1[67]\.'
74- echohl WarningMsg
75- echo " Warning: Node.js" matchstr (s: client .node_version, ' ^\d\+' ) " is end-of-life and support will be dropped in a future release of copilot.vim."
76- echohl NONE
77- elseif exists (' s:client.node_version_warning' )
73+ if exists (' s:client.node_version_warning' )
7874 echohl WarningMsg
7975 echo ' Warning:' s: client .node_version_warning
8076 echohl NONE
@@ -202,9 +198,9 @@ function! copilot#Complete(...) abort
202198 if ! a: 0
203199 return completion.Await ()
204200 else
205- call copilot#client#Result (completion, a: 1 )
201+ call copilot#client#Result (completion, function ( a: 1, [ b: _copilot ]) )
206202 if a: 0 > 1
207- call copilot#client#Error (completion, a: 2 )
203+ call copilot#client#Error (completion, function ( a: 2, [ b: _copilot ]) )
208204 endif
209205 endif
210206endfunction
@@ -371,21 +367,29 @@ function! s:UpdatePreview() abort
371367 endtry
372368endfunction
373369
374- function ! s: HandleTriggerResult (result) abort
375- if ! exists (' b:_copilot' )
376- return
370+ function ! s: HandleTriggerResult (state , result) abort
371+ let a: state .suggestions = type (a: result ) == type ([]) ? a: result : get (empty (a: result ) ? {} : a: result , ' items' , [])
372+ let a: state .choice = 0
373+ if get (b: , ' _copilot' ) is # a: state
374+ call s: UpdatePreview ()
375+ endif
376+ endfunction
377+
378+ function ! s: HandleTriggerError (state , result) abort
379+ let a: state .suggestions = []
380+ let a: state .choice = 0
381+ let a: state .error = a: result
382+ if get (b: , ' _copilot' ) is # a: state
383+ call s: UpdatePreview ()
377384 endif
378- let b: _copilot .suggestions = type (a: result ) == type ([]) ? a: result : get (empty (a: result ) ? {} : a: result , ' items' , [])
379- let b: _copilot .choice = 0
380- call s: UpdatePreview ()
381385endfunction
382386
383387function ! copilot#Suggest () abort
384388 if ! s: Running ()
385389 return ' '
386390 endif
387391 try
388- call copilot#Complete (function (' s:HandleTriggerResult' ), function (' s:HandleTriggerResult ' ))
392+ call copilot#Complete (function (' s:HandleTriggerResult' ), function (' s:HandleTriggerError ' ))
389393 catch
390394 call copilot#logger#Exception ()
391395 endtry
0 commit comments