Skip to content

fix(nvim): fix job management in cmd runner. #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lua/vectorcode/integrations/codecompanion/func_calling_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,18 @@ return check_cli_wrap(function(opts)
if opts.ls_on_start then
job_runner = cc_common.initialise_runner(opts.use_lsp)
if job_runner ~= nil then
vim.list_extend(guidelines, {
" - The following projects are indexed by VectorCode and are available for you to search in:",
})
vim.list_extend(
guidelines,
vim.tbl_map(function(s)
return string.format(" - %s", s["project-root"])
end, job_runner.run({ "ls", "--pipe" }, -1, 0))
)
local projects = job_runner.run({ "ls", "--pipe" }, -1, 0)
if vim.islist(projects) and #projects > 0 then
vim.list_extend(guidelines, {
" - The following projects are indexed by VectorCode and are available for you to search in:",
})
vim.list_extend(
guidelines,
vim.tbl_map(function(s)
return string.format(" - %s", s["project-root"])
end, projects)
)
end
end
end
local root = vim.fs.root(0, { ".vectorcode", ".git" })
Expand Down
30 changes: 18 additions & 12 deletions lua/vectorcode/jobrunner/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,28 @@ function runner.run_async(args, callback, bufnr)
local ok, decoded = pcall(vim.json.decode, table.concat(result, ""))
if callback ~= nil then
if ok then
logger.debug(
"cmd jobrunner result:\n",
vim.tbl_map(function(item)
item.document = nil
item.chunk = nil
return item
end, vim.deepcopy(result))
)
callback(decoded, self:stderr_result())
callback(decoded or {}, self:stderr_result())
if vim.islist(result) then
logger.debug(
"cmd jobrunner result:\n",
vim.tbl_map(function(item)
if type(item) == "table" then
item.document = nil
item.chunk = nil
end
return item
end, vim.deepcopy(result))
)
end
else
logger.warn("cmd runner: failed to decode result:\n", result)
callback({ result }, self:stderr_result())
logger.warn("cmd runner: failed to decode result:\n", result)
end
end
end,
})
jobs[job.pid] = job
job:start()
jobs[job.pid] = job
return tonumber(job.pid)
end

Expand All @@ -59,7 +63,9 @@ function runner.run(args, timeout_ms, bufnr)
err = error
end, bufnr)
if pid ~= nil then
jobs[pid]:wait(timeout_ms)
vim.wait(timeout_ms, function()
return res ~= nil or err ~= nil
end)
jobs[pid] = nil
return res, err
else
Expand Down