@@ -10,6 +10,7 @@ local M = {
1010 capabilities = nil ,
1111 config = nil ,
1212 node_version = nil ,
13+ node_version_error = nil ,
1314 startup_error = nil ,
1415}
1516
@@ -44,13 +45,14 @@ if not lsp_start then
4445 end
4546end
4647
47- --- @return string
48+ --- @return string node_version
49+ --- @return nil | string node_version_error
4850function M .get_node_version ()
4951 if not M .node_version then
5052 local node = config .get (" copilot_node_command" )
5153
5254 local cmd = { node , " --version" }
53- local cmd_output_table = vim .fn .systemlist (cmd , nil , false )
55+ local cmd_output_table = vim .fn .executable ( node ) == 1 and vim . fn . systemlist (cmd , nil , false ) or { " " }
5456 local cmd_output = cmd_output_table [# cmd_output_table ]
5557 local cmd_exit_code = vim .v .shell_error
5658
@@ -59,33 +61,25 @@ function M.get_node_version()
5961 local node_version_minor = tonumber (string.match (node_version , " ^%d+%.(%d+)%." )) or 0
6062
6163 if node_version_major == 0 then
62- local err = " [Copilot] Could not determine Node.js version"
63- vim .notify (err , vim .log .levels .WARN )
64- vim .api .nvim_echo ({
65- {
66- table.concat ({
67- err ,
68- " -----------" ,
69- " (exit code) " .. tostring (cmd_exit_code ),
70- " (output) " .. cmd_output ,
71- " -----------" ,
72- }, " \n " ),
73- " MoreMsg" ,
74- },
75- }, true , {})
64+ M .node_version_error = table.concat ({
65+ " Could not determine Node.js version" ,
66+ " -----------" ,
67+ " (exit code) " .. tostring (cmd_exit_code ),
68+ " (output) " .. cmd_output ,
69+ " -----------" ,
70+ }, " \n " )
7671 elseif
7772 node_version_major < 16
7873 or (node_version_major == 16 and node_version_minor < 14 )
7974 or (node_version_major == 17 and node_version_minor < 3 )
8075 then
81- local err = string.format (" [Copilot] Node.js version 18.x or newer required but found %s" , node_version )
82- vim .notify (err , vim .log .levels .WARN )
76+ M .node_version_error = string.format (" Node.js version 18.x or newer required but found %s" , node_version )
8377 end
8478
8579 M .node_version = node_version or " "
8680 end
8781
88- return M .node_version
82+ return M .node_version , M . node_version_error
8983end
9084
9185function M .buf_is_attached (bufnr )
@@ -208,15 +202,17 @@ local function prepare_client_config(overrides)
208202 end )
209203 end ,
210204 on_exit = function (code , _signal , client_id )
211- if code > 0 then
205+ if M . id == client_id then
212206 vim .schedule (function ()
213- -- in case for unsupported node
214- M .get_node_version ()
207+ M .teardown ()
208+ M .id = nil
209+ M .capabilities = nil
215210 end )
216211 end
217- if M .id == client_id then
218- M .id = nil
219- M .capabilities = nil
212+ if code > 0 then
213+ vim .schedule (function ()
214+ require (" copilot.command" ).status ()
215+ end )
220216 end
221217 end ,
222218 handlers = {
0 commit comments