From 25b6f70085c08890faa7cef7030358bd5c402646 Mon Sep 17 00:00:00 2001 From: Zhe Yu Date: Sun, 27 Jul 2025 19:14:46 +0800 Subject: [PATCH 1/3] refactor(nvim): Migrate from `references` to `context` --- .../integrations/codecompanion/init.lua | 7 +++++++ .../integrations/codecompanion/query_tool.lua | 16 ++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lua/vectorcode/integrations/codecompanion/init.lua b/lua/vectorcode/integrations/codecompanion/init.lua index 08ce26e8..736d02ef 100644 --- a/lua/vectorcode/integrations/codecompanion/init.lua +++ b/lua/vectorcode/integrations/codecompanion/init.lua @@ -7,6 +7,13 @@ return { chat = { ---@param component_cb (fun(result:VectorCode.QueryResult):string)? make_slash_command = check_cli_wrap(function(component_cb) + vim.deprecate( + "vectorcode slash command", + "vectorcode tool/extension", + "0.8.0", + "VectorCode", + true + ) return { description = "Add relevant files from the codebase.", ---@param chat CodeCompanion.Chat diff --git a/lua/vectorcode/integrations/codecompanion/query_tool.lua b/lua/vectorcode/integrations/codecompanion/query_tool.lua index 89f7ebc1..c84ecf1f 100644 --- a/lua/vectorcode/integrations/codecompanion/query_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/query_tool.lua @@ -164,18 +164,18 @@ local result_tracker = {} ---@param chat CodeCompanion.Chat ---@return VectorCode.QueryResult[] local filter_results = function(results, chat) - local existing_refs = chat.refs or {} + local existing_refs = chat.context_items or {} existing_refs = vim .iter(existing_refs) :filter( - ---@param ref CodeCompanion.Chat.Ref + ---@param ref CodeCompanion.Chat.ContextItem function(ref) return ref.source == cc_common.tool_result_source or ref.path or ref.bufnr end ) :map( - ---@param ref CodeCompanion.Chat.Ref + ---@param ref CodeCompanion.Chat.ContextItem function(ref) if ref.source == cc_common.tool_result_source then return ref.id @@ -386,10 +386,14 @@ return check_cli_wrap(function(opts) end end - if opts.no_duplicate and agent.chat.refs ~= nil and action.deduplicate then + if + opts.no_duplicate + and agent.chat.context_items ~= nil + and action.deduplicate + then -- exclude files that has been added to the context local existing_files = { "--exclude" } - for _, ref in pairs(agent.chat.refs) do + for _, ref in pairs(agent.chat.context_items) do if ref.source == cc_common.tool_result_source then table.insert(existing_files, ref.id) elseif type(ref.path) == "string" then @@ -596,7 +600,7 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES if not opts.chunk_mode then for _, result in pairs(stdout.raw_results) do -- skip referencing because there will be multiple chunks with the same path (id). - agent.chat.references:add({ + agent.chat.context:add({ source = cc_common.tool_result_source, id = result.path, path = result.path, From 9dbb071d173f6b611a3fee73993139c6fe712771 Mon Sep 17 00:00:00 2001 From: Zhe Yu Date: Mon, 28 Jul 2025 17:33:33 +0800 Subject: [PATCH 2/3] fix(nvim): type annotation --- lua/vectorcode/integrations/codecompanion/query_tool.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/vectorcode/integrations/codecompanion/query_tool.lua b/lua/vectorcode/integrations/codecompanion/query_tool.lua index c84ecf1f..4e955bf6 100644 --- a/lua/vectorcode/integrations/codecompanion/query_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/query_tool.lua @@ -156,8 +156,8 @@ local process_result = function(result) end ---@alias chat_id integer ----@alias result_id string ----@type +---@alias results table +---@type table local result_tracker = {} ---@param results VectorCode.QueryResult[] From adaae185c41981088c01d06a580a6d978d7e465e Mon Sep 17 00:00:00 2001 From: Zhe Yu Date: Mon, 28 Jul 2025 17:47:41 +0800 Subject: [PATCH 3/3] fix(nvim): Use `context` and `refs` interchangeably --- .../integrations/codecompanion/query_tool.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lua/vectorcode/integrations/codecompanion/query_tool.lua b/lua/vectorcode/integrations/codecompanion/query_tool.lua index 4e955bf6..906353dc 100644 --- a/lua/vectorcode/integrations/codecompanion/query_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/query_tool.lua @@ -164,7 +164,7 @@ local result_tracker = {} ---@param chat CodeCompanion.Chat ---@return VectorCode.QueryResult[] local filter_results = function(results, chat) - local existing_refs = chat.context_items or {} + local existing_refs = chat.context_items or chat.refs or {} existing_refs = vim .iter(existing_refs) @@ -345,6 +345,7 @@ return check_cli_wrap(function(opts) "CodeCompanion query tool called with the following arguments:\n", action ) + job_runner = cc_common.initialise_runner(opts.use_lsp) assert(job_runner ~= nil, "Jobrunner not initialised!") assert( @@ -386,14 +387,12 @@ return check_cli_wrap(function(opts) end end - if - opts.no_duplicate - and agent.chat.context_items ~= nil - and action.deduplicate - then + -- TODO: remove the `chat.refs` compatibility code when the upstream PR is released. + local context_items = agent.chat.context_items or agent.chat.refs + if opts.no_duplicate and context_items ~= nil and action.deduplicate then -- exclude files that has been added to the context local existing_files = { "--exclude" } - for _, ref in pairs(agent.chat.context_items) do + for _, ref in pairs(context_items) do if ref.source == cc_common.tool_result_source then table.insert(existing_files, ref.id) elseif type(ref.path) == "string" then @@ -598,9 +597,10 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES string.format("**VectorCode Tool**: Retrieved %d %s(s)", stdout.count, mode) ) if not opts.chunk_mode then + local context = agent.chat.context or agent.chat.references for _, result in pairs(stdout.raw_results) do -- skip referencing because there will be multiple chunks with the same path (id). - agent.chat.context:add({ + context:add({ source = cc_common.tool_result_source, id = result.path, path = result.path,