3333
3434let s: config_hosts = s: config_root . ' /hosts.json'
3535
36- function ! s: JsonBody (response) abort
37- if get (a: response .headers, ' content-type' , ' ' ) = ~# ' ^application/json\>'
38- let body = a: response .body
39- return json_decode (type (body) == v: t_list ? join (body) : body)
40- else
41- throw ' Copilot: expected application/json but got ' . get (a: response .headers, ' content-type' , ' no content type' )
42- endif
43- endfunction
44-
45- function ! copilot#HttpRequest (url, options , ... ) abort
46- return call (' copilot#Call' , [' httpRequest' , extend ({' url' : a: url , ' timeout' : 30000 }, a: options )] + a: 000 )
47- endfunction
48-
4936function ! s: StatusNotification (params, ... ) abort
5037 let status = get (a: params , ' status' , ' ' )
5138 if status == ? ' error'
@@ -526,30 +513,6 @@ endfunction
526513
527514let s: commands = {}
528515
529- function s: NetworkStatusMessage () abort
530- let err = copilot#Agent ().StartupError ()
531- if ! empty (err)
532- return err
533- endif
534- try
535- let info = copilot#agent#EditorInfo ()
536- let response = copilot#HttpRequest (' https://copilot-proxy.githubusercontent.com/_ping' ,
537- \ {' timeout' : 5000 , ' headers' : {
538- \ ' Editor-Version' : info.editorInfo.name . ' /' . info.editorInfo.version ,
539- \ ' Editor-Plugin-Version' : info.editorPluginInfo.name . ' /' . info.editorPluginInfo.version ,
540- \ }})
541- if response.status == 466
542- return " Server error:\n " . substitute (response.body, " \n $" , ' ' , ' ' )
543- endif
544- catch /\%( timed out after \| getaddrinfo \|ERR_HTTP2_INVALID_SESSION\)/
545- call copilot#logger#Exception ()
546- return ' Server connectivity issue'
547- catch
548- call copilot#logger#Exception ()
549- endtry
550- return ' '
551- endfunction
552-
553516function ! s: EnabledStatusMessage () abort
554517 let buf_disabled = s: BufferDisabled ()
555518 if ! s: has_ghost_text && bufwinid (' copilot://' ) == -1
@@ -605,9 +568,9 @@ function! s:commands.status(opts) abort
605568 return
606569 endif
607570
608- let network_status = s: NetworkStatusMessage ()
609- if ! empty (network_status )
610- echo ' Copilot: ' . network_status
571+ let startup_error = copilot#Agent (). StartupError ()
572+ if ! empty (startup_error )
573+ echo ' Copilot: ' . startup_error
611574 return
612575 endif
613576
@@ -630,9 +593,10 @@ function! s:commands.signout(opts) abort
630593endfunction
631594
632595function ! s: commands .setup (opts) abort
633- let network_status = s: NetworkStatusMessage ()
634- if ! empty (network_status)
635- return ' echoerr ' . string (' Copilot: ' . network_status)
596+ let startup_error = copilot#Agent ().StartupError ()
597+ if ! empty (startup_error)
598+ echo ' Copilot: ' . startup_error
599+ return
636600 endif
637601
638602 let browser = copilot#Browser ()
0 commit comments