Skip to content

Commit 10f75eb

Browse files
authored
refactor(nvim): Migrate from references to context for codecompanion.nvim tools. (#259)
* refactor(nvim): Migrate from `references` to `context` * fix(nvim): type annotation * fix(nvim): Use `context` and `refs` interchangeably
1 parent 65ca748 commit 10f75eb

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

lua/vectorcode/integrations/codecompanion/init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ return {
77
chat = {
88
---@param component_cb (fun(result:VectorCode.QueryResult):string)?
99
make_slash_command = check_cli_wrap(function(component_cb)
10+
vim.deprecate(
11+
"vectorcode slash command",
12+
"vectorcode tool/extension",
13+
"0.8.0",
14+
"VectorCode",
15+
true
16+
)
1017
return {
1118
description = "Add relevant files from the codebase.",
1219
---@param chat CodeCompanion.Chat

lua/vectorcode/integrations/codecompanion/query_tool.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,26 @@ local process_result = function(result)
156156
end
157157

158158
---@alias chat_id integer
159-
---@alias result_id string
160-
---@type <chat_id: result_id>
159+
---@alias results table<string,boolean>
160+
---@type table<chat_id, results>
161161
local result_tracker = {}
162162

163163
---@param results VectorCode.QueryResult[]
164164
---@param chat CodeCompanion.Chat
165165
---@return VectorCode.QueryResult[]
166166
local filter_results = function(results, chat)
167-
local existing_refs = chat.refs or {}
167+
local existing_refs = chat.context_items or chat.refs or {}
168168

169169
existing_refs = vim
170170
.iter(existing_refs)
171171
:filter(
172-
---@param ref CodeCompanion.Chat.Ref
172+
---@param ref CodeCompanion.Chat.ContextItem
173173
function(ref)
174174
return ref.source == cc_common.tool_result_source or ref.path or ref.bufnr
175175
end
176176
)
177177
:map(
178-
---@param ref CodeCompanion.Chat.Ref
178+
---@param ref CodeCompanion.Chat.ContextItem
179179
function(ref)
180180
if ref.source == cc_common.tool_result_source then
181181
return ref.id
@@ -345,6 +345,7 @@ return check_cli_wrap(function(opts)
345345
"CodeCompanion query tool called with the following arguments:\n",
346346
action
347347
)
348+
348349
job_runner = cc_common.initialise_runner(opts.use_lsp)
349350
assert(job_runner ~= nil, "Jobrunner not initialised!")
350351
assert(
@@ -386,10 +387,12 @@ return check_cli_wrap(function(opts)
386387
end
387388
end
388389

389-
if opts.no_duplicate and agent.chat.refs ~= nil and action.deduplicate then
390+
-- TODO: remove the `chat.refs` compatibility code when the upstream PR is released.
391+
local context_items = agent.chat.context_items or agent.chat.refs
392+
if opts.no_duplicate and context_items ~= nil and action.deduplicate then
390393
-- exclude files that has been added to the context
391394
local existing_files = { "--exclude" }
392-
for _, ref in pairs(agent.chat.refs) do
395+
for _, ref in pairs(context_items) do
393396
if ref.source == cc_common.tool_result_source then
394397
table.insert(existing_files, ref.id)
395398
elseif type(ref.path) == "string" then
@@ -594,9 +597,10 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
594597
string.format("**VectorCode Tool**: Retrieved %d %s(s)", stdout.count, mode)
595598
)
596599
if not opts.chunk_mode then
600+
local context = agent.chat.context or agent.chat.references
597601
for _, result in pairs(stdout.raw_results) do
598602
-- skip referencing because there will be multiple chunks with the same path (id).
599-
agent.chat.references:add({
603+
context:add({
600604
source = cc_common.tool_result_source,
601605
id = result.path,
602606
path = result.path,

0 commit comments

Comments
 (0)