Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions lua/vectorcode/integrations/codecompanion/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ return {
end
return job_runner
end,

---Convert `path` to a relative path if it's within the current project.
---When `base` is `nil`, this function will attempt to find a project root
---or use `cwd`.
---@param path string
---@param base? string
---@return string
cleanup_path = function(path, base)
base = base or vim.fs.root(0, { ".vectorcode", ".git" }) or vim.uv.cwd() or "."
return vim.fs.relpath(base, path) or path
end,
}
10 changes: 7 additions & 3 deletions lua/vectorcode/integrations/codecompanion/files_ls_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ return function(opts)
type = "function",
["function"] = {
name = tool_name,
description = "Retrieve a list of files that have been added to the database for a given project.",
description = [[
Retrieve a list of files that have been added to the database for a given project.
**ABSOLUTE PATHS** in the results indicate that the files are OUTSIDE of the current working directories and you can **ONLY** access them via the VectorCode tools.
**RELATIVE PATHS** in the results indicate that the files are INSIDE the current project. You can use VectorCode tools or any other tools that the user provided to interact with them. They are relative to the project root.
]],
parameters = {
type = "object",
properties = {
Expand All @@ -73,7 +77,7 @@ return function(opts)
---@param tools CodeCompanion.Tools
---@param stdout string[][]
success = function(_, tools, _, stdout)
stdout = stdout[1]
stdout = stdout[#stdout]
local user_message
for i, col in ipairs(stdout) do
if i == 1 then
Expand All @@ -84,7 +88,7 @@ return function(opts)
end
tools.chat:add_tool_output(
tools.tool,
string.format("<path>%s</path>", col),
string.format("<path>%s</path>", cc_common.cleanup_path(col)),
user_message
)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/vectorcode/integrations/codecompanion/ls_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Where relevant, use paths from this tool as the `project_root` parameter in othe
---@param tools CodeCompanion.Tools
---@param stdout VectorCode.LsResult[][]
success = function(_, tools, _, stdout)
stdout = stdout[1]
stdout = stdout[#stdout]
local user_message
for i, col in ipairs(stdout) do
if i == 1 then
Expand Down
25 changes: 24 additions & 1 deletion lua/vectorcode/integrations/codecompanion/query_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,25 @@ When summarising the code, pay extra attention on information related to the que
end
end

---@param results VectorCode.QueryResult[]
---@return VectorCode.QueryResult[]
local function cleanup_paths(results)
local cwd = vim.fs.root(0, { ".vectorcode", ".git" }) or vim.uv.cwd()
if cwd then
results = vim
.iter(results)
:map(
---@param res VectorCode.QueryResult
function(res)
res.path = cc_common.cleanup_path(res.path)
return res
end
)
:totable()
end
return results
end

---@param opts VectorCode.CodeCompanion.QueryToolOpts?
---@return CodeCompanion.Tools.Tool
return check_cli_wrap(function(opts)
Expand Down Expand Up @@ -436,6 +455,8 @@ return check_cli_wrap(function(opts)
result = filter_results(result, tools.chat)
end

result = cleanup_paths(result)

local max_result = #result
if opts.max_num > 0 then
max_result = math.min(tonumber(opts.max_num) or 1, max_result)
Expand Down Expand Up @@ -477,6 +498,8 @@ Make use of the line numbers (NOT THE XML TAGS) when you're quoting the source c
Include one single command call for VectorCode each time.
You may include multiple keywords in the command.
**The project root option MUST be a valid path on the filesystem. It can only be one of the results from the `vectorcode_ls` tool or from user input**
**ABSOLUTE PATHS** in the results indicate that the files are OUTSIDE of the current working directories and you can **ONLY** access them via the VectorCode tools.
**RELATIVE PATHS** in the results indicate that the files are INSIDE the current project. You can use VectorCode tools or any other tools that the user provided to interact with them. They are relative to the project root.
]],
parameters = {
type = "object",
Expand Down Expand Up @@ -572,7 +595,7 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
---@param cmd QueryToolArgs
---@param stdout VectorCode.CodeCompanion.QueryToolResult[]
success = function(self, tools, cmd, stdout)
stdout = stdout[1]
stdout = stdout[#stdout]
logger.info(
("CodeCompanion tool with command %s finished."):format(vim.inspect(cmd))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ The paths should be accurate (DO NOT ASSUME A PATH EXIST) and case case-sensitiv
---@param cmd VectoriseToolArgs
---@param stdout VectorCode.VectoriseResult[]
success = function(self, tools, cmd, stdout)
stdout = stdout[1]
stdout = stdout[#stdout]
tools.chat:add_tool_output(
self,
string.format(
Expand Down
Loading