Skip to content

Commit f0b41fb

Browse files
committed
feat(command): show if node.js not found for 'version'
1 parent db62371 commit f0b41fb

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lua/copilot/client.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,24 @@ end
4242
local copilot_node_version = nil
4343
function M.get_node_version()
4444
if not copilot_node_version then
45-
copilot_node_version = string.match(
46-
table.concat(vim.fn.systemlist(config.get("copilot_node_command") .. " --version", nil, false)),
45+
local node_version = string.match(
46+
table.concat(vim.fn.systemlist(config.get("copilot_node_command") .. " --version", nil, false)) or "",
4747
"v(%S+)"
4848
)
4949

50-
local node_version_major = tonumber(string.match(copilot_node_version, "^(%d+)%."))
50+
if not node_version then
51+
error("[Copilot] Node.js not found")
52+
end
53+
54+
local node_version_major = tonumber(string.match(node_version, "^(%d+)%."))
5155
if node_version_major < 16 then
5256
vim.notify(
5357
string.format("[Copilot] Node.js version 16.x or newer required but found %s", copilot_node_version),
5458
vim.log.levels.ERROR
5559
)
5660
end
61+
62+
copilot_node_version = node_version
5763
end
5864
return copilot_node_version
5965
end

lua/copilot/command.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ function mod.version()
1919
if client then
2020
local _, data = a.get_version(client)
2121
lines[#lines + 1] = "copilot/dist/agent.js" .. " " .. data.version
22-
lines[#lines + 1] = "Node.js" .. " " .. c.get_node_version()
2322
else
2423
lines[#lines + 1] = "copilot/dist/agent.js" .. " " .. "not running"
2524
end
2625

26+
local found_node_version, node_version = pcall(c.get_node_version)
27+
lines[#lines + 1] = "Node.js" .. " " .. (found_node_version and node_version or "not found")
28+
2729
vim.api.nvim_echo(
2830
vim.tbl_map(function(line)
2931
return { line .. "\n" }

0 commit comments

Comments
 (0)