@@ -13,6 +13,8 @@ local vc_config = require("vectorcode.config")
1313local check_cli_wrap = vc_config .check_cli_wrap
1414local notify_opts = vc_config .notify_opts
1515
16+ local tool_result_source = " VectorCodeToolResult"
17+
1618--- @param t table | string
1719--- @return string
1820local function flatten_table_to_string (t )
@@ -22,10 +24,6 @@ local function flatten_table_to_string(t)
2224 return table.concat (vim .iter (t ):flatten (math.huge ):totable (), " \n " )
2325end
2426
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-
2927local job_runner = nil
3028--- @param use_lsp boolean
3129local function initialise_runner (use_lsp )
@@ -63,7 +61,7 @@ local make_tool = check_cli_wrap(function(opts)
6361 use_lsp = false ,
6462 auto_submit = { ls = false , query = false },
6563 ls_on_start = false ,
66- no_duplicate = false ,
64+ no_duplicate = true ,
6765 }, opts or {})
6866 local capping_message = " "
6967 if opts .max_num > 0 then
@@ -112,12 +110,12 @@ local make_tool = check_cli_wrap(function(opts)
112110 end
113111 end
114112
115- if opts .no_duplicate then
113+ if opts .no_duplicate and agent . chat . refs ~= nil then
116114 -- exclude files that has been added to the context
117115 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 )
116+ for _ , ref in pairs (agent .chat . refs ) do
117+ if ref . source == tool_result_source then
118+ table.insert (existing_files , ref . id )
121119 end
122120 end
123121 if # existing_files > 1 then
@@ -318,6 +316,7 @@ Remember:
318316 success = function (agent , cmd , stdout )
319317 stdout = stdout [1 ]
320318 if cmd .command == " query" then
319+ agent .chat .ui :unlock_buf ()
321320 for i , file in pairs (stdout ) do
322321 if opts .max_num < 0 or i <= opts .max_num then
323322 agent .chat :add_message ({
@@ -334,13 +333,12 @@ Remember:
334333 file .path ,
335334 file .document
336335 ),
337- }, { 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
336+ }, { visible = false , id = file .path })
337+ agent .chat .references :add ({
338+ source = tool_result_source ,
339+ id = file .path ,
340+ opts = { visible = false },
341+ })
344342 end
345343 end
346344 elseif cmd .command == " ls" then
0 commit comments