Skip to content

Commit eacea36

Browse files
committed
feat(nvim): avoid retrieving files that is already present in the context.
1 parent 16e78ed commit eacea36

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lua/vectorcode/integrations/codecompanion.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
---@field use_lsp boolean?
88
---@field auto_submit table<string, boolean>?
99
---@field ls_on_start boolean?
10+
---@field no_duplicate boolean?
1011

1112
local vc_config = require("vectorcode.config")
1213
local check_cli_wrap = vc_config.check_cli_wrap
@@ -21,6 +22,10 @@ local function flatten_table_to_string(t)
2122
return table.concat(vim.iter(t):flatten(math.huge):totable(), "\n")
2223
end
2324

25+
---@alias path string
26+
---@type table<CodeCompanion.Chat, table<path, boolean>> For each chat, keep a record of what files has been sent.
27+
local added_context = {}
28+
2429
local job_runner = nil
2530
---@param use_lsp boolean
2631
local function initialise_runner(use_lsp)
@@ -58,6 +63,7 @@ local make_tool = check_cli_wrap(function(opts)
5863
use_lsp = false,
5964
auto_submit = { ls = false, query = false },
6065
ls_on_start = false,
66+
no_duplicate = false,
6167
}, opts or {})
6268
local capping_message = ""
6369
if opts.max_num > 0 then
@@ -105,6 +111,20 @@ local make_tool = check_cli_wrap(function(opts)
105111
)
106112
end
107113
end
114+
115+
if opts.no_duplicate then
116+
-- exclude files that has been added to the context
117+
local existing_files = { "--exclude" }
118+
for path, ok in pairs(added_context[agent.chat] or {}) do
119+
if ok then
120+
table.insert(existing_files, path)
121+
end
122+
end
123+
if #existing_files > 1 then
124+
vim.list_extend(args, existing_files)
125+
end
126+
end
127+
108128
job_runner.run_async(args, function(result, error)
109129
vim.schedule(function()
110130
if opts.auto_submit[action.command] then
@@ -315,6 +335,12 @@ Remember:
315335
file.document
316336
),
317337
}, { visible = false })
338+
if opts.no_duplicate then
339+
if added_context[agent.chat] == nil then
340+
added_context[agent.chat] = {}
341+
end
342+
added_context[agent.chat][file.path] = true
343+
end
318344
end
319345
end
320346
elseif cmd.command == "ls" then

0 commit comments

Comments
 (0)