Skip to content
Merged
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
26 changes: 25 additions & 1 deletion lua/vectorcode/integrations/codecompanion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
---@field use_lsp boolean?
---@field auto_submit table<string, boolean>?
---@field ls_on_start boolean?
---@field no_duplicate boolean?

local vc_config = require("vectorcode.config")
local check_cli_wrap = vc_config.check_cli_wrap
local notify_opts = vc_config.notify_opts

local tool_result_source = "VectorCodeToolResult"

---@param t table|string
---@return string
local function flatten_table_to_string(t)
Expand Down Expand Up @@ -58,6 +61,7 @@ local make_tool = check_cli_wrap(function(opts)
use_lsp = false,
auto_submit = { ls = false, query = false },
ls_on_start = false,
no_duplicate = true,
}, opts or {})
local capping_message = ""
if opts.max_num > 0 then
Expand Down Expand Up @@ -105,6 +109,20 @@ local make_tool = check_cli_wrap(function(opts)
)
end
end

if opts.no_duplicate and agent.chat.refs ~= nil then
-- exclude files that has been added to the context
local existing_files = { "--exclude" }
for _, ref in pairs(agent.chat.refs) do
if ref.source == tool_result_source then
table.insert(existing_files, ref.id)
end
end
if #existing_files > 1 then
vim.list_extend(args, existing_files)
end
end

job_runner.run_async(args, function(result, error)
vim.schedule(function()
if opts.auto_submit[action.command] then
Expand Down Expand Up @@ -298,6 +316,7 @@ Remember:
success = function(agent, cmd, stdout)
stdout = stdout[1]
if cmd.command == "query" then
agent.chat.ui:unlock_buf()
for i, file in pairs(stdout) do
if opts.max_num < 0 or i <= opts.max_num then
agent.chat:add_message({
Expand All @@ -314,7 +333,12 @@ Remember:
file.path,
file.document
),
}, { visible = false })
}, { visible = false, id = file.path })
agent.chat.references:add({
source = tool_result_source,
id = file.path,
opts = { visible = false },
})
end
end
elseif cmd.command == "ls" then
Expand Down