Skip to content

Commit 72648b8

Browse files
committed
fix(nvim): convert vim.NIL args to nil in codecompanion tools
1 parent 915ad56 commit 72648b8

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

lua/vectorcode/integrations/codecompanion/files_ls_tool.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ return function(opts)
2828
---@return nil|{ status: string, data: string }
2929
function(tools, action, _, cb)
3030
local args = { "files", "ls", "--pipe" }
31+
action = utils.fix_nil(action)
3132
if action ~= nil then
3233
action.project_root = action.project_root
3334
or vim.fs.root(0, { ".vectorcode", ".git" })

lua/vectorcode/integrations/codecompanion/files_rm_tool.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ The value should be one of the following:
5858
---@return nil|{ status: string, data: string }
5959
function(tools, action, _, cb)
6060
local args = { "files", "rm", "--pipe" }
61+
action = utils.fix_nil(action)
6162
if action.project_root then
6263
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root))
6364
if utils.is_directory(project_root) then
@@ -85,7 +86,7 @@ The value should be one of the following:
8586
args,
8687
---@param result VectoriseResult
8788
function(result, error, code, _)
88-
if result then
89+
if code == 0 then
8990
cb({ status = "success", data = result })
9091
else
9192
cb({ status = "error", data = { error = error, code = code } })

lua/vectorcode/integrations/codecompanion/query_tool.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ return check_cli_wrap(function(opts)
385385
"CodeCompanion query tool called with the following arguments:\n",
386386
action
387387
)
388-
388+
action = utils.fix_nil(action)
389389
if action.deduplicate == nil then
390390
action.deduplicate = opts.no_duplicate
391391
end

lua/vectorcode/integrations/codecompanion/vectorise_tool.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ The value should be one of the following:
7676
---@return nil|{ status: string, data: string }
7777
function(tools, action, _, cb)
7878
local args = { "vectorise", "--pipe" }
79+
action = utils.fix_nil(action)
7980
if action.project_root then
8081
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root))
8182
if utils.is_directory(project_root) then

lua/vectorcode/utils.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,20 @@ M.flatten_table_to_string = function(t, fallback)
201201
return table.concat(flattened, "\n")
202202
end
203203

204+
---Convert any `vim.NIL` instances to `nil` in lua.
205+
---@generic Obj: any
206+
---@param obj Obj
207+
---@return Obj
208+
function M.fix_nil(obj)
209+
if obj == vim.NIL then
210+
return nil
211+
end
212+
if type(obj) == "table" then
213+
for k, v in pairs(obj) do
214+
obj[k] = M.fix_nil(v)
215+
end
216+
end
217+
return obj
218+
end
219+
204220
return M

0 commit comments

Comments
 (0)