Repository navigation
Expand file tree
/
Copy pathfiles_rm_tool.lua
More file actions
114 lines (108 loc) · 3.52 KB
/
Copy pathfiles_rm_tool.lua
File metadata and controls
114 lines (108 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---@module "codecompanion"
local cc_common = require("vectorcode.integrations.codecompanion.common")
local vc_config = require("vectorcode.config")
local utils = require("vectorcode.utils")
local default_opts = {
use_lsp = vc_config.get_user_config().async_backend == "lsp",
requires_approval = true,
include_in_toolbox = false,
}
---@alias FilesRmArgs { paths: string[], project_root: string? }
---@param opts VectorCode.CodeCompanion.FilesRmToolOpts
---@return CodeCompanion.Tools
return function(opts)
opts = vim.tbl_deep_extend("force", default_opts, opts or {})
local tool_name = "vectorcode_files_rm"
local job_runner = cc_common.initialise_runner(opts.use_lsp)
---@type CodeCompanion.Tools|{}
return {
name = tool_name,
schema = {
type = "function",
["function"] = {
name = tool_name,
description = "Remove files from the VectorCode database. The files will remain in the file system.",
parameters = {
type = "object",
properties = {
paths = {
type = "array",
items = { type = "string" },
description = "Paths to the files to be removed from the database.",
},
project_root = {
type = "string",
description = [[
The project that the files belong to.
The value should be one of the following:
- One of the paths from the `vectorcode_ls` tool;
- User input;
- `null` (omit this parameter), which means the current project, if found.
]],
},
},
required = { "paths" },
},
strict = true,
},
},
cmds = {
---@param tools CodeCompanion.Tools
---@param action VectoriseToolArgs
---@return nil|{ status: string, data: string }
function(tools, action, _, cb)
local args = { "files", "rm", "--pipe" }
action = utils.fix_nil(action)
if action.project_root then
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root))
if utils.is_directory(project_root) then
vim.list_extend(args, { "--project_root", project_root })
else
return { status = "error", data = "Invalid path " .. project_root }
end
end
if action.paths == nil or #action.paths == 0 then
return { status = "error", data = "Please specify at least one path." }
end
vim.list_extend(
args,
vim
.iter(action.paths)
:filter(
---@param item string
function(item)
return utils.is_file(item)
end
)
:totable()
)
job_runner.run_async(
args,
---@param result VectoriseResult
function(result, error, code, _)
if code == 0 then
cb({ status = "success", data = result })
else
cb({ status = "error", data = { error = error, code = code } })
end
end,
tools.chat.bufnr
)
end,
},
output = {
---@param self CodeCompanion.Tools.Tool
prompt = function(self, _)
return string.format(
"Remove %d files from VectorCode database?",
#self.args.paths
)
end,
---@param self CodeCompanion.Tools.Tool
---@param tools CodeCompanion.Tools
success = function(self, tools, _, _)
tools.chat:add_tool_output(self, "**VectorCode `files_rm` tool**: successful.")
end,
},
}
end