Skip to content

Commit 653bbdc

Browse files
committed
perf(client): make node.js version check lazy and optional
1 parent 3bfdf96 commit 653bbdc

File tree

2 files changed

+36
-40
lines changed

2 files changed

+36
-40
lines changed

lua/copilot/client.lua

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,41 @@ if not lsp_start then
4444
end
4545
end
4646

47-
---@return string|nil
47+
---@return string
4848
function M.get_node_version()
49+
if not M.node_version then
50+
local node = config.get("copilot_node_command")
51+
52+
local cmd = node .. " --version"
53+
local cmd_output = table.concat(vim.fn.systemlist(cmd, nil, false))
54+
local cmd_exit_code = vim.v.shell_error
55+
56+
local node_version = string.match(cmd_output, "^v(%S+)") or ""
57+
local node_version_major = tonumber(string.match(node_version, "^(%d+)%.")) or 0
58+
59+
if node_version_major == 0 then
60+
local err = "[Copilot] Could not determine Node.js version"
61+
vim.notify(err, vim.log.levels.WARN)
62+
vim.api.nvim_echo({
63+
{
64+
table.concat({
65+
err,
66+
"-----------",
67+
"(exit code) " .. tostring(cmd_exit_code),
68+
" (output) " .. cmd_output,
69+
"-----------",
70+
}, "\n"),
71+
"MoreMsg",
72+
},
73+
}, true, {})
74+
elseif node_version_major < 16 then
75+
local err = string.format("[Copilot] Node.js version 16.x or newer required but found %s", node_version)
76+
vim.notify(err, vim.log.levels.WARN)
77+
end
78+
79+
M.node_version = node_version or ""
80+
end
81+
4982
return M.node_version
5083
end
5184

@@ -131,43 +164,6 @@ local function prepare_client_config(overrides)
131164
return
132165
end
133166

134-
if not M.node_version then
135-
local cmd = node .. " --version"
136-
local cmd_output = table.concat(vim.fn.systemlist(cmd, nil, false))
137-
local cmd_exit_code = vim.v.shell_error
138-
139-
local node_version = string.match(cmd_output, "v(%S+)") or ""
140-
local node_version_major = tonumber(string.match(node_version, "^(%d+)%.")) or 0
141-
142-
if node_version_major == 0 then
143-
local err = "Could not determine Node.js version"
144-
vim.notify("[Copilot] " .. err, vim.log.levels.ERROR)
145-
M.startup_error = table.concat({
146-
err,
147-
"\n",
148-
"-----------",
149-
"\n",
150-
"(exit code) ",
151-
tostring(cmd_exit_code),
152-
"\n",
153-
" (output) ",
154-
cmd_output,
155-
"\n",
156-
"-----------",
157-
})
158-
return
159-
end
160-
161-
if node_version_major < 16 then
162-
local err = string.format("Node.js version 16.x or newer required but found %s", node_version)
163-
vim.notify("[Copilot] " .. err, vim.log.levels.ERROR)
164-
M.startup_error = err
165-
return
166-
end
167-
168-
M.node_version = node_version
169-
end
170-
171167
local agent_path = vim.api.nvim_get_runtime_file("copilot/index.js", false)[1]
172168
if vim.fn.filereadable(agent_path) == 0 then
173169
local err = string.format("Could not find agent.js (bad install?) : %s", agent_path)
@@ -198,7 +194,7 @@ local function prepare_client_config(overrides)
198194
local set_editor_info_params = util.get_editor_info()
199195
set_editor_info_params.editorInfo.version = set_editor_info_params.editorInfo.version
200196
.. " + Node.js "
201-
.. (M.get_node_version() or "")
197+
.. M.get_node_version()
202198
set_editor_info_params.editorConfiguration = util.get_editor_configuration()
203199
set_editor_info_params.networkProxy = util.get_network_proxy()
204200
api.set_editor_info(client, set_editor_info_params, function(err)

lua/copilot/command.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function mod.version()
2424
end
2525

2626
local node_version = c.get_node_version()
27-
lines[#lines + 1] = "Node.js" .. " " .. (node_version or "not found")
27+
lines[#lines + 1] = "Node.js" .. " " .. (#node_version == 0 and "(unknown)" or node_version)
2828

2929
vim.api.nvim_echo(
3030
vim.tbl_map(function(line)

0 commit comments

Comments
 (0)