Skip to content

Commit 4d76007

Browse files
committed
fix: add compatibilty for older versions
1 parent 7138ae6 commit 4d76007

File tree

8 files changed

+38
-18
lines changed

8 files changed

+38
-18
lines changed

docs/neovim/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ The following are the common options that all tools supports:
234234
if you're using [fidget.nvim](https://github.com/j-hui/fidget.nvim). Default:
235235
`true` if `async_backend` is set to `"lsp"` in `setup()`. Otherwise, it'll be
236236
`false`;
237-
- `requires_approval`: whether CodeCompanion.nvim asks for your approval before
238-
executing the tool call. Default: `false` for `ls` and `query`; `true` for
237+
- `require_approval_before`: whether CodeCompanion.nvim asks for your approval before
238+
executing the tool call. _Use `requires_approval` if you're using CodeCompanion.nvim `<v18.0.0`_.
239+
Default: `false` for `ls` and `query`; `true` for
239240
`vectorise`;
240241
- `include_in_toolbox`: whether this tool should be included in
241242
`vectorcode_toolbox`. Default: `true` for `query`, `vectorise` and `ls`,

lua/codecompanion/_extensions/vectorcode/init.lua

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ local utils = require("vectorcode.utils")
2222

2323
---@type VectorCode.CodeCompanion.ExtensionOpts|{}
2424
local default_extension_opts = {
25+
---@type table<sub_cmd, VectorCode.CodeCompanion.ToolOpts|{}>
2526
tool_opts = {
2627
-- NOTE: the other default opts are defined in the source code files of the tools.
2728
-- `include_in_toolbox` is here so that the extension setup works as expected.
2829
ls = { include_in_toolbox = true },
2930
query = { include_in_toolbox = true },
30-
vectorise = { include_in_toolbox = true },
31+
vectorise = {
32+
requires_approval = true,
33+
require_approval_before = true,
34+
include_in_toolbox = true,
35+
},
3136
files_ls = {},
32-
files_rm = {},
37+
files_rm = { require_approval_before = true, requires_approval = true },
3338
},
3439
tool_group = { enabled = true, collapse = true, extras = {} },
3540
prompt_library = require("vectorcode.integrations.codecompanion.prompts.presets"),
@@ -58,15 +63,32 @@ end
5863
local M = {
5964
---@param opts VectorCode.CodeCompanion.ExtensionOpts
6065
setup = vc_config.check_cli_wrap(function(opts)
66+
if
67+
opts
68+
and opts.tool_opts
69+
and vim.iter(opts.tool_opts):any(function(_, v)
70+
return v.requires_approval ~= nil
71+
end)
72+
then
73+
vim.deprecate(
74+
"requires_approval",
75+
"require_approval_before",
76+
"1.0.0",
77+
"VectorCode",
78+
false
79+
)
80+
end
6181
opts = vim.tbl_deep_extend("force", default_extension_opts, opts or {})
6282
opts.tool_opts = merge_tool_opts(opts.tool_opts)
6383
logger.info("Received codecompanion extension opts:\n", opts)
6484
local cc_config = require("codecompanion.config").config
6585
local cc_integration = require("vectorcode.integrations").codecompanion
6686
local cc_chat_integration = cc_integration.chat
87+
88+
local interactions = cc_config.strategies or cc_config.interactions
6789
for _, sub_cmd in pairs(valid_tools) do
6890
local tool_name = string.format("vectorcode_%s", sub_cmd)
69-
if cc_config.interactions.chat.tools[tool_name] ~= nil then
91+
if interactions.chat.tools[tool_name] ~= nil then
7092
vim.notify(
7193
string.format(
7294
"There's an existing tool named `%s`. Please either remove it or rename it.",
@@ -82,10 +104,16 @@ local M = {
82104
)
83105
)
84106
else
85-
cc_config.interactions.chat.tools[tool_name] = {
107+
local require_approval = opts.tool_opts[sub_cmd].requires_approval
108+
or opts.tool_opts[sub_cmd].require_approval_before
109+
110+
interactions.chat.tools[tool_name] = {
86111
description = string.format("Run VectorCode %s tool", sub_cmd),
87112
callback = cc_chat_integration.make_tool(sub_cmd, opts.tool_opts[sub_cmd]),
88-
opts = { requires_approval = opts.tool_opts[sub_cmd].requires_approval },
113+
opts = {
114+
requires_approval = require_approval,
115+
require_approval_before = require_approval,
116+
},
89117
}
90118
logger.info(string.format("%s tool has been created.", tool_name))
91119
end
@@ -110,7 +138,7 @@ local M = {
110138
vim.inspect(included_tools)
111139
)
112140
)
113-
cc_config.interactions.chat.tools.groups["vectorcode_toolbox"] = {
141+
interactions.chat.tools.groups["vectorcode_toolbox"] = {
114142
opts = { collapse_tools = opts.tool_group.collapse },
115143
description = "Use VectorCode to automatically build and retrieve repository-level context.",
116144
tools = included_tools,

lua/vectorcode/integrations/codecompanion/files_ls_tool.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ local utils = require("vectorcode.utils")
66

77
local default_opts = {
88
use_lsp = vc_config.get_user_config().async_backend == "lsp",
9-
requires_approval = false,
10-
include_in_toolbox = false,
119
}
1210

1311
---@param opts VectorCode.CodeCompanion.FilesLsToolOpts

lua/vectorcode/integrations/codecompanion/files_rm_tool.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ local utils = require("vectorcode.utils")
66

77
local default_opts = {
88
use_lsp = vc_config.get_user_config().async_backend == "lsp",
9-
requires_approval = true,
10-
include_in_toolbox = false,
119
}
1210

1311
---@alias FilesRmArgs { paths: string[], project_root: string? }

lua/vectorcode/integrations/codecompanion/ls_tool.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ local logger = vc_config.logger
77
---@type VectorCode.CodeCompanion.LsToolOpts
88
local default_ls_options = {
99
use_lsp = vc_config.get_user_config().async_backend == "lsp",
10-
requires_approval = false,
11-
include_in_toolbox = true,
1210
}
1311

1412
---@param opts VectorCode.CodeCompanion.LsToolOpts|{}|nil

lua/vectorcode/integrations/codecompanion/query_tool.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ local job_runner = nil
1616
---@type VectorCode.CodeCompanion.QueryToolOpts
1717
local default_query_options = {
1818
use_lsp = vc_config.get_user_config().async_backend == "lsp",
19-
requires_approval = false,
20-
include_in_toolbox = true,
2119
max_num = { chunk = -1, document = -1 },
2220
default_num = { chunk = 50, document = 10 },
2321
no_duplicate = true,

lua/vectorcode/integrations/codecompanion/vectorise_tool.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ local logger = vc_config.logger
1212
---@type VectorCode.CodeCompanion.VectoriseToolOpts
1313
local default_vectorise_options = {
1414
use_lsp = vc_config.get_user_config().async_backend == "lsp",
15-
requires_approval = true,
16-
include_in_toolbox = true,
1715
}
1816

1917
---@param opts VectorCode.CodeCompanion.VectoriseToolOpts|{}|nil

lua/vectorcode/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
--- Whether to use the LSP backend. Default: `false`
7777
---@field use_lsp boolean?
7878
---@field requires_approval boolean?
79+
---@field require_approval_before boolean?
7980
--- Whether this tool should be included in `vectorcode_toolbox`
8081
---@field include_in_toolbox boolean?
8182

0 commit comments

Comments
 (0)