Skip to content

Commit 9f07033

Browse files
author
Zhe Yu
committed
fix(nvim): fix tool option type conversions
1 parent d3a8643 commit 9f07033

3 files changed

Lines changed: 41 additions & 18 deletions

File tree

lua/vectorcode/integrations/codecompanion/common.lua

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,16 @@ local vc_config = require("vectorcode.config")
33
local notify_opts = vc_config.notify_opts
44
local logger = vc_config.logger
55

6-
---@class VectorCode.CodeCompanion.ToolOpts
7-
---@field max_num integer|{document:integer, chunk: integer}|nil
8-
---@field default_num integer|{document:integer, chunk: integer}|nil
9-
---@field include_stderr boolean?
10-
---@field use_lsp boolean?
11-
---@field auto_submit table<string, boolean>?
12-
---@field ls_on_start boolean?
13-
---@field no_duplicate boolean?
14-
---@field chunk_mode boolean?
15-
166
---@type VectorCode.CodeCompanion.ToolOpts
177
local default_options = {
18-
max_num = -1,
19-
default_num = 10,
8+
max_num = { chunk = -1, document = -1 },
9+
default_num = { chunk = 50, document = 10 },
2010
include_stderr = false,
2111
use_lsp = false,
2212
auto_submit = { ls = false, query = false },
2313
ls_on_start = false,
2414
no_duplicate = true,
25-
only_chunks = false,
15+
chunk_mode = false,
2616
}
2717

2818
return {
@@ -46,6 +36,7 @@ return {
4636
{ use_lsp = vc_config.get_user_config().async_backend == "lsp" }
4737
)
4838
end
39+
opts = vim.tbl_deep_extend("force", default_options, opts)
4940
if type(opts.default_num) == "table" then
5041
if opts.chunk_mode then
5142
opts.default_num = opts.default_num.chunk
@@ -68,33 +59,34 @@ return {
6859
"max_num should be an integer or a table: {chunk: integer, document: integer}"
6960
)
7061
end
71-
return vim.tbl_deep_extend("force", default_options, opts)
62+
return opts
7263
end,
7364

7465
---@param result VectorCode.Result
7566
---@return string
7667
process_result = function(result)
68+
local llm_message
7769
if result.chunk then
7870
-- chunk mode
79-
local chunk =
71+
llm_message =
8072
string.format("<path>%s</path><chunk>%s</chunk>", result.path, result.chunk)
8173
if result.start_line and result.end_line then
82-
chunk = chunk
74+
llm_message = llm_message
8375
.. string.format(
8476
"<start_line>%d</start_line><end_line>%d</end_line>",
8577
result.start_line,
8678
result.end_line
8779
)
8880
end
89-
return chunk
9081
else
9182
-- full document mode
92-
return string.format(
83+
llm_message = string.format(
9384
"<path>%s</path><content>%s</content>",
9485
result.path,
9586
result.document
9687
)
9788
end
89+
return llm_message
9890
end,
9991
---@param use_lsp boolean
10092
---@return VectorCode.JobRunner

lua/vectorcode/integrations/codecompanion/func_calling_tool.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ local job_runner = nil
1111
---@return CodeCompanion.Agent.Tool
1212
return check_cli_wrap(function(opts)
1313
opts = cc_common.get_tool_opts(opts)
14+
assert(
15+
type(opts.max_num) == "number" and type(opts.default_num) == "number",
16+
string.format("Options are not correctly formatted:%s", vim.inspect(opts))
17+
)
1418
---@type "file"|"chunk"
1519
local mode
1620
if opts.chunk_mode then

lua/vectorcode/types.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,30 @@
5656
---@field buf_is_enabled fun(bufnr: integer?): boolean Checks if a buffer has been enabled.
5757
---@field make_prompt_component fun(bufnr: integer?, component_cb: (fun(result: VectorCode.Result): string)?): {content: string, count: integer} Compile the retrieval results into a string.
5858
---@field async_check fun(check_item: string?, on_success: fun(out: vim.SystemCompleted)?, on_failure: fun(out: vim.SystemCompleted)?) Checks if VectorCode has been configured properly for your project.
59+
60+
--- This class defines the options available to the CodeCompanion tool.
61+
---@class VectorCode.CodeCompanion.ToolOpts
62+
--- Maximum number of results provided to the LLM.
63+
--- You may set this to a table to configure different values for document/chunk mode.
64+
--- When set to negative values, it means unlimited.
65+
--- Default: `{ document = -1, chunk = -1 }`
66+
---@field max_num integer|{document:integer, chunk: integer}|nil
67+
--- Default number of results provided to the LLM.
68+
--- This value is written in the system prompt and tool description.
69+
--- Users may ask the LLM to request a different number of results in the chat.
70+
--- You may set this to a table to configure different values for document/chunk mode.
71+
--- Default: `{ document = 10, chunk = 50 }`
72+
---@field default_num integer|{document:integer, chunk: integer}|nil
73+
--- Whether the stderr should be provided back to the chat
74+
---@field include_stderr boolean?
75+
--- Whether to use the LSP backend. Default: `false`
76+
---@field use_lsp boolean?
77+
--- Whether to automatically submit the result (no longer necessary in recent CodeCompanion releases). Default: `false`
78+
---@field auto_submit table<string, boolean>?
79+
--- Whether to run `vectorcode ls` and tell the LLM about the indexed projects when initialising the tool. Default: `false`
80+
---@field ls_on_start boolean?
81+
--- Whether to avoid duplicated references. Default: `true`
82+
---@field no_duplicate boolean?
83+
--- Whether to send chunks instead of full files to the LLM. Default: `false`
84+
--- > Make sure you adjust `max_num` and `default_num` accordingly.
85+
---@field chunk_mode boolean?

0 commit comments

Comments
 (0)