Skip to content

Commit

Permalink
feat: allow skipping node check for alternative runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Feb 2, 2024
1 parent 691e138 commit ffda6cf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
10 changes: 6 additions & 4 deletions lua/sg/cody/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ M.start = function(opts, callback)
M.client = nil
end

local ok, reason = require("sg.utils").valid_node_executable(config.node_executable)
if not ok then
require("sg.notify").INVALID_NODE(reason)
return callback()
if not config.skip_node_check then
local ok, reason = require("sg.utils").valid_node_executable(config.node_executable)
if not ok then
require("sg.notify").INVALID_NODE(reason)
return callback()
end
end

---@type {["chat/updateMessageInProgress"]: fun(noti: CodyChatUpdateMessageInProgressNoti?)}
Expand Down
2 changes: 2 additions & 0 deletions lua/sg/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
---@field accept_tos boolean?: Accept the TOS without being prompted
---@field download_binaries boolean?: Default true, download latest release from Github
---@field node_executable string?: path to node executable
---@field skip_node_check boolean?: Useful if using other js runtime
---@field cody_agent string?: path to the cody-agent js bundle
---@field on_attach function?: function to run when attaching to sg://<file> buffers

Expand All @@ -29,6 +30,7 @@ local config = {
enable_cody = true,
download_binaries = true,
node_executable = "node",
skip_node_check = false,
cody_agent = vim.api.nvim_get_runtime_file("dist/cody-agent.js", false)[1],

get_nvim_agent = function()
Expand Down
65 changes: 35 additions & 30 deletions lua/sg/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,45 +100,50 @@ end
local report_agent = function()
local config = require "sg.config"

local ok, reason = require("sg.utils").valid_node_executable(config.node_executable)
if not ok then
vim.health.error(string.format("Invalid node executable (%s): %s", config.node_executable, vim.inspect(reason)))
return false
end

if 1 ~= vim.fn.executable(config.node_executable) then
vim.health.error(string.format("config.node_executable (%s) not executable", config.node_executable))
return false
if config.skip_node_check then
vim.health.info(string.format("Skipped node check. Executable is: %s", config.node_executable))
else
local result = require("sg.utils").system({ config.node_executable, "--version" }, { text = true }):wait()
if result.code ~= 0 then
vim.health.error(
string.format(
"config.node_executable (%s) failed to run `%s --version`",
config.node_executable,
config.node_executable
)
)
local ok, reason = require("sg.utils").valid_node_executable(config.node_executable)
if not ok then
vim.health.error(string.format("Invalid node executable (%s): %s", config.node_executable, vim.inspect(reason)))
return false
end

for _, msg in ipairs(vim.split(result.stdout, "\n")) do
vim.health.info(msg)
end
for _, msg in ipairs(vim.split(result.stderr, "\n")) do
vim.health.info(msg)
end
if 1 ~= vim.fn.executable(config.node_executable) then
vim.health.error(string.format("config.node_executable (%s) not executable", config.node_executable))
return false
else
vim.health.ok(
string.format(
"Found `%s` (config.node_executable) is executable.\n Version: '%s'",
config.node_executable,
reason
local result = require("sg.utils").system({ config.node_executable, "--version" }, { text = true }):wait()
if result.code ~= 0 then
vim.health.error(
string.format(
"config.node_executable (%s) failed to run `%s --version`",
config.node_executable,
config.node_executable
)
)
)

for _, msg in ipairs(vim.split(result.stdout, "\n")) do
vim.health.info(msg)
end
for _, msg in ipairs(vim.split(result.stderr, "\n")) do
vim.health.info(msg)
end
else
vim.health.ok(
string.format(
"Found `%s` (config.node_executable) is executable.\n Version: '%s'",
config.node_executable,
reason
)
)
end
end
end

if not config.cody_agent then
vim.health.error "Unable to find cody_agent `cody-agent.js` file"
return false
else
vim.health.ok(string.format("Found `cody-agent`: %s", config.cody_agent))
end
Expand Down

0 comments on commit ffda6cf

Please sign in to comment.