Skip to content

Commit 6798c9f

Browse files
author
Zhe Yu
committed
docs(nvim): fix type annotations
1 parent 5ac5502 commit 6798c9f

2 files changed

Lines changed: 33 additions & 32 deletions

File tree

lua/codecompanion/_extensions/vectorcode/init.lua

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
---@alias sub_cmd "ls"|"query"|"vectorise"|"files_ls"|"files_rm"
44

55
---@class VectorCode.CodeCompanion.ExtensionOpts
6-
--- A table where the keys are the subcommand name (`ls`, `query`, `vectorise`)
6+
---A table where the keys are the subcommand name (`ls`, `query`, `vectorise`, etc.)
77
--- and the values are their config options.
8-
---@field tool_opts table<sub_cmd, VectorCode.CodeCompanion.ToolOpts>
9-
--- Whether to add a tool group that contains all vectorcode tools.
10-
---@field tool_group VectorCode.CodeCompanion.ToolGroupOpts
8+
---@field tool_opts? table<sub_cmd|"*", VectorCode.CodeCompanion.ToolOpts>
9+
---Options related to the `vectorcode_toolbox` tool group
10+
---@field tool_group? VectorCode.CodeCompanion.ToolGroupOpts
1111
---Prompt library that automatically creates VectorCode collections on local files
1212
---and set up prompts to let LLM search from certain directories.
1313
---
1414
---The keys should be the human-readable name of the prompt (as they'd appear in
1515
---the action menu), and values would be `VectorCode.CodeCompanion.PromptFactory.Opts`
1616
---objects.
17-
---@field prompt_library table<string, VectorCode.CodeCompanion.PromptFactory.Opts>
17+
---@field prompt_library? table<string, VectorCode.CodeCompanion.PromptFactory.Opts>
1818

1919
local vc_config = require("vectorcode.config")
2020
local logger = vc_config.logger
@@ -25,22 +25,20 @@ local default_extension_opts = {
2525
tool_opts = {
2626
-- NOTE: the other default opts are defined in the source code files of the tools.
2727
-- `include_in_toolbox` is here so that the extension setup works as expected.
28-
2928
ls = { include_in_toolbox = true },
3029
query = { include_in_toolbox = true },
3130
vectorise = { include_in_toolbox = true },
3231
files_ls = {},
3332
files_rm = {},
3433
},
3534
tool_group = { enabled = true, collapse = true, extras = {} },
36-
3735
prompt_library = require("vectorcode.integrations.codecompanion.prompts.presets"),
3836
}
3937

4038
---@type sub_cmd[]
4139
local valid_tools = { "ls", "query", "vectorise", "files_ls", "files_rm" }
4240

43-
---@param tool_opts table<sub_cmd, VectorCode.CodeCompanion.ToolOpts>
41+
---@param tool_opts table<sub_cmd|"*", VectorCode.CodeCompanion.ToolOpts>
4442
---@return table<sub_cmd, VectorCode.CodeCompanion.ToolOpts>
4543
local function merge_tool_opts(tool_opts)
4644
local wildcard_opts = tool_opts["*"]
@@ -50,7 +48,9 @@ local function merge_tool_opts(tool_opts)
5048
tool_opts[tool_name] = vim.tbl_deep_extend("force", wildcard_opts, opts)
5149
end
5250
end
51+
tool_opts["*"] = nil
5352
end
53+
---@cast tool_opts table<sub_cmd, VectorCode.CodeCompanion.ToolOpts>
5454
return tool_opts
5555
end
5656

@@ -130,14 +130,15 @@ local M = {
130130
vc_config.notify_opts
131131
)
132132
end
133-
if type(prompt_opts.project_root) == "function" then
134-
prompt_opts.project_root = prompt_opts.project_root()
133+
local project_root = prompt_opts.project_root
134+
if type(project_root) == "function" then
135+
project_root = project_root()
135136
end
136-
if not utils.is_directory(prompt_opts.project_root) then
137+
if not utils.is_directory(project_root) then
137138
vim.notify(
138139
string.format(
139140
"`%s` is not a valid directory for CodeCompanion prompt library.\nSkipping `%s`.",
140-
prompt_opts.project_root,
141+
project_root,
141142
name
142143
),
143144
vim.log.levels.WARN,

lua/vectorcode/types.lua

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353

5454
---Options for the registration of an async cache for a buffer.
5555
---@class VectorCode.RegisterOpts: VectorCode.QueryOpts
56-
---@field debounce integer? Seconds. Default: 10
57-
---@field events string|string[]|nil autocmd events that triggers async jobs. Default: `{"BufWritePost", "InsertEnter", "BufReadPost"}`
58-
---@field single_job boolean? Whether to restrict to 1 async job per buffer. Default: false
59-
---@field query_cb VectorCode.QueryCallback? Function that accepts the buffer ID and returns the query message(s). Default: `require("vectorcode.utils").make_surrounding_lines_cb(-1)`
60-
---@field run_on_register boolean? Whether to run the query when registering. Default: false
61-
---@field project_root string?
56+
---@field debounce? integer Seconds. Default: 10
57+
---@field events? string|string[] autocmd events that triggers async jobs. Default: `{"BufWritePost", "InsertEnter", "BufReadPost"}`
58+
---@field single_job? boolean Whether to restrict to 1 async job per buffer. Default: false
59+
---@field query_cb? VectorCode.QueryCallback Function that accepts the buffer ID and returns the query message(s). Default: `require("vectorcode.utils").make_surrounding_lines_cb(-1)`
60+
---@field run_on_register? boolean Whether to run the query when registering. Default: false
61+
---@field project_root? string
6262

6363
---A unified interface used by `lsp` backend and `default` backend
6464
---@class VectorCode.CacheBackend
@@ -96,29 +96,29 @@
9696
--- Users may ask the LLM to request a different number of results in the chat.
9797
--- You may set this to a table to configure different values for document/chunk mode.
9898
--- Default: `{ document = 10, chunk = 50 }`
99-
---@field default_num integer|{document:integer, chunk: integer}|nil
99+
---@field default_num? integer|{document:integer, chunk: integer}
100100
--- Whether to avoid duplicated references. Default: `true`
101101
---@field no_duplicate boolean?
102102
--- Whether to send chunks instead of full files to the LLM. Default: `false`
103103
--- > Make sure you adjust `max_num` and `default_num` accordingly.
104-
---@field chunk_mode boolean?
105-
---@field summarise VectorCode.CodeCompanion.SummariseOpts?
104+
---@field chunk_mode? boolean
105+
---@field summarise? VectorCode.CodeCompanion.SummariseOpts
106106

107107
---@class VectorCode.CodeCompanion.VectoriseToolOpts: VectorCode.CodeCompanion.ToolOpts
108108

109109
---@class VectorCode.CodeCompanion.ToolGroupOpts
110-
--- Whether to register the tool group
111-
---@field enabled boolean
112-
--- Whether to show the individual tools in the references
113-
---@field collapse boolean
114-
--- Other tools that you'd like to include in `vectorcode_toolbox`
115-
---@field extras string[]
110+
---Whether to register the tool group
111+
---@field enabled? boolean
112+
---Whether to show the individual tools in the references
113+
---@field collapse? boolean
114+
---Other tools that you'd like to include in `vectorcode_toolbox`
115+
---@field extras? string[]
116116

117117
--- The result of the query tool should be structured in the following table
118118
---@class VectorCode.CodeCompanion.QueryToolResult
119119
---@field raw_results VectorCode.QueryResult[]
120120
---@field count integer
121-
---@field summary string|nil
121+
---@field summary? string
122122

123123
---@class VectorCode.CodeCompanion.SummariseOpts
124124
---A boolean flag that controls whether summarisation should be enabled.
@@ -128,13 +128,13 @@
128128
---This function recieves 2 parameters:
129129
--- - `CodeCompanion.Chat`: the chat object;
130130
--- - `VectorCode.QueryResult[]`: a list of query results.
131-
---@field enabled boolean|(fun(chat: CodeCompanion.Chat, results: VectorCode.QueryResult[]):boolean)|nil
131+
---@field enabled? boolean|(fun(chat: CodeCompanion.Chat, results: VectorCode.QueryResult[]):boolean)
132132
---The adapter used for the summarisation task. When set to `nil`, the adapter from the current chat will be used.
133-
---@field adapter string|CodeCompanion.HTTPAdapter|fun():CodeCompanion.HTTPAdapter|nil
133+
---@field adapter? string|CodeCompanion.HTTPAdapter|fun():CodeCompanion.HTTPAdapter
134134
---The system prompt sent to the summariser model.
135135
---When set to a function, it'll recieve the default system prompt as the only parameter,
136136
---and should return the new (full) system prompt. This allows you to customise or rewrite the system prompt.
137-
---@field system_prompt string|(fun(original_prompt: string): string)
137+
---@field system_prompt? string|(fun(original_prompt: string): string)
138138
---When set to true, include the query messages so that the LLM may make task-related summarisations.
139139
---This happens __after__ the `system_prompt` callback processing
140-
---@field query_augmented boolean
140+
---@field query_augmented? boolean

0 commit comments

Comments
 (0)