Skip to content
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
16 changes: 15 additions & 1 deletion lua/vectorcode/integrations/codecompanion/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ return {
if type(t) == "string" then
return t
end
return table.concat(vim.iter(t):flatten(math.huge):totable(), "\n")

-- Handle empty tables or tables with empty strings
local flattened = vim
.iter(t)
:flatten(math.huge)
:filter(function(item)
return type(item) == "string" and vim.trim(item) ~= ""
end)
:totable()

if #flattened == 0 then
return "Unknown error occurred"
end

return table.concat(flattened, "\n")
end,

---@param use_lsp boolean
Expand Down
23 changes: 16 additions & 7 deletions lua/vectorcode/integrations/codecompanion/query_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ return check_cli_wrap(function(opts)
args
)

job_runner.run_async(args, function(result, error)
job_runner.run_async(args, function(result, error, code)
local err_string = cc_common.flatten_table_to_string(error)

if vim.islist(result) and #result > 0 and result[1].path ~= nil then ---@cast result VectorCode.QueryResult[]
local summary_opts = vim.deepcopy(opts.summarise) or {}
if type(summary_opts.enabled) == "function" then
Expand Down Expand Up @@ -496,13 +498,20 @@ return check_cli_wrap(function(opts)
})
end)
else
if type(error) == "table" then
error = cc_common.flatten_table_to_string(error)
-- Only report as error if we have a meaningful error or non-zero exit code
if (err_string and err_string ~= "") or code ~= 0 then
cb({
status = "error",
data = ((err_string ~= "") and err_string)
or "VectorCode query tool failed to execute.",
})
else
-- Successful operation but no results found
cb({
status = "success",
data = { raw_results = {}, count = 0 },
})
end
cb({
status = "error",
data = error,
})
end
end, tools.chat.bufnr)
end,
Expand Down
Loading