Skip to content

Commit e4f2be0

Browse files
committed
docs(nvim): inline documentation.
1 parent 65a45b2 commit e4f2be0

File tree

4 files changed

+63
-29
lines changed

4 files changed

+63
-29
lines changed

lua/vectorcode/cacher.lua

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,14 @@ local function async_runner(query_message, buf_nr)
107107
end
108108

109109
M.register_buffer = vc_config.check_cli_wrap(
110-
---@param bufnr integer?
111-
---@param opts VectorCode.RegisterOpts?
110+
---This function registers a buffer to be cached by VectorCode. The
111+
---registered buffer can be aquired by the `query_from_cache` API.
112+
---The retrieval of the files occurs in the background, so this
113+
---function will not block the main thread.
114+
---
115+
---NOTE: this function uses an autocommand to track the changes to the buffer and trigger retrieval.
116+
---@param bufnr integer? Default to the current buffer.
117+
---@param opts VectorCode.RegisterOpts? Async options.
112118
function(bufnr, opts)
113119
if bufnr == 0 or bufnr == nil then
114120
bufnr = vim.api.nvim_get_current_buf()
@@ -166,6 +172,10 @@ M.register_buffer = vc_config.check_cli_wrap(
166172
)
167173

168174
M.deregister_buffer = vc_config.check_cli_wrap(
175+
---This function deregisters a buffer from VectorCode. This will kill all
176+
---running jobs, delete cached results, and deregister the autocommands
177+
---associated with the buffer. If the caching has not been registered, an
178+
---error notification will bef ired.
169179
---@param bufnr integer?
170180
---@param opts {notify:boolean}
171181
function(bufnr, opts)
@@ -204,6 +214,8 @@ M.buf_is_registered = function(bufnr)
204214
end
205215

206216
M.query_from_cache = vc_config.check_cli_wrap(
217+
---This function queries VectorCode from cache. Returns an array of results. Each item
218+
---of the array is in the format of `{path="path/to/your/code.lua", document="document content"}`.
207219
---@param bufnr integer?
208220
---@param opts {notify: boolean}?
209221
---@return VectorCode.Result[]
@@ -233,8 +245,11 @@ M.query_from_cache = vc_config.check_cli_wrap(
233245
end
234246
)
235247

248+
---@alias ComponentCallback fun(result:VectorCode.Result):string
249+
250+
---Compile the retrieval results into a string.
236251
---@param bufnr integer
237-
---@param component_cb (fun(result:VectorCode.Result):string)?
252+
---@param component_cb ComponentCallback? The component callback that formats a retrieval result.
238253
---@return {content:string, count:integer}
239254
function M.make_prompt_component(bufnr, component_cb)
240255
if bufnr == 0 or bufnr == nil then
@@ -257,6 +272,8 @@ function M.make_prompt_component(bufnr, component_cb)
257272
return { content = final_component, count = #retrieval }
258273
end
259274

275+
---Checks if VectorCode has been configured properly for your project.
276+
---See the CLI manual for details.
260277
---@param check_item string?
261278
---@param on_success fun(out: vim.SystemCompleted)?
262279
---@param on_failure fun(out: vim.SystemCompleted?)?

lua/vectorcode/init.lua

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ local get_config = vc_config.get_user_config
66
local notify_opts = vc_config.notify_opts
77

88
M.query = vc_config.check_cli_wrap(
9-
---@param query_message string|string[]
10-
---@param opts VectorCode.QueryOpts?
11-
---@param callback fun(result:VectorCode.Result[])?
12-
---@return VectorCode.Result[]?
9+
---This function wraps the `query` subcommand of the VectorCode CLI. When used without the `callback` parameter,
10+
---this function works as a synchronous function and return the results. Otherwise, this function will run async
11+
---and the results are accessible by the `callback` function (the results will be passed as the argument to the
12+
---callback).
13+
---@param query_message string|string[] Query message(s) to send to the `vecctorcode query` command
14+
---@param opts VectorCode.QueryOpts? A table of config options. If nil, the default config or `setup` config will be used.
15+
---@param callback fun(result:VectorCode.Result[])? Use the result async style.
16+
---@return VectorCode.Result[]? An array of results.
1317
function(query_message, opts, callback)
1418
opts = vim.tbl_deep_extend("force", vc_config.get_query_opts(), opts or {})
1519
if opts.n_query == 0 then
@@ -83,8 +87,12 @@ M.query = vc_config.check_cli_wrap(
8387
)
8488

8589
M.vectorise = vc_config.check_cli_wrap(
86-
---@param files string|string[]
87-
---@param project_root string?
90+
---This function wraps the `vectorise` subcommand. By default this function doesn't pass a `--project_root` flag.
91+
---The command will be run from the current working directory, and the normal project root detection logic in the
92+
---CLI will work as normal. You may also pass a `project_root` as the second argument, in which case the
93+
---`--project_root` will be passed.
94+
---@param files string|string[] Files to vectorise.
95+
---@param project_root string? Add the `--project_root` flag and the passed argument to the command.
8896
function(files, project_root)
8997
local args = { "--pipe", "vectorise" }
9098
if project_root ~= nil then
@@ -147,8 +155,8 @@ M.vectorise = vc_config.check_cli_wrap(
147155
end
148156
)
149157

150-
---@param check_item string?
151-
---@param stdout_cb fun(stdout: vim.SystemCompleted)?
158+
---@param check_item string? See `vectorcode check` documentation.
159+
---@param stdout_cb fun(stdout: vim.SystemCompleted)? Gives user access to the exit code, stdout and signal.
152160
---@return boolean
153161
function M.check(check_item, stdout_cb)
154162
if not vc_config.has_cli() then

lua/vectorcode/types.lua

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1+
---Type definition of the retrieval result.
12
---@class VectorCode.Result
2-
---@field path string
3-
---@field document string
3+
---@field path string Path to the file
4+
---@field document string Content of the file
45

6+
---Type definitions for the cache of a buffer.
57
---@class VectorCode.Cache
6-
---@field enabled boolean
7-
---@field jobs table<integer, boolean>
8-
---@field last_run integer?
9-
---@field options VectorCode.RegisterOpts
10-
---@field retrieval VectorCode.Result[]?
8+
---@field enabled boolean Whether the async jobs are enabled or not. If the buffer is disabled, no cache will be generated for it.
9+
---@field jobs table<integer, boolean> keeps track of running jobs.
10+
---@field last_run integer? Last time the query ran, in seconds from epoch.
11+
---@field options VectorCode.RegisterOpts The options that the buffer was registered with.
12+
---@field retrieval VectorCode.Result[]? The latest retrieval.
1113

14+
---Type definitions for options accepted by `query` API.
1215
---@class VectorCode.QueryOpts
13-
---@field exclude_this boolean
14-
---@field n_query integer
15-
---@field notify boolean
16-
---@field timeout_ms number
16+
---@field exclude_this boolean Whether to exclude the current buffer. Default: true
17+
---@field n_query integer Number of results.
18+
---@field notify boolean Notify on new results and other key moments.
19+
---@field timeout_ms number Timeout (in milliseconds) for running a vectorcode command. Default: 5000
1720

21+
---Options passed to `setup`.
1822
---@class VectorCode.Opts : VectorCode.QueryOpts
19-
---@field async_opts VectorCode.RegisterOpts
23+
---@field async_opts VectorCode.RegisterOpts Default options to use for registering a new buffer for async cache.
2024

25+
---Options for the registration of an async cache for a buffer.
2126
---@class VectorCode.RegisterOpts: VectorCode.QueryOpts
22-
---@field debounce integer
23-
---@field events string|string[]
24-
---@field single_job boolean
25-
---@field query_cb VectorCode.QueryCallback
26-
---@field run_on_register boolean
27+
---@field debounce integer Seconds. Default: 10
28+
---@field events string|string[] autocmd events that triggers async jobs. Default: `{"BufWritePost", "InsertEnter", "BufReadPost"}`
29+
---@field single_job boolean Whether to restrict to 1 async job per buffer. Default: false
30+
---@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)`
31+
---@field run_on_register boolean Whether to run the query when registering. Default: false

lua/vectorcode/utils.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ end
2828

2929
---@alias VectorCode.QueryCallback fun(bufnr:integer?):string|string[]
3030

31+
---Retrieves all LSP document symbols from the current buffer, and use the symbols
32+
---as query messages. Fallbacks to `make_surrounding_lines_cb` if
33+
---`textDocument_documentSymbol` is not accessible.
3134
---@return VectorCode.QueryCallback
3235
function M.make_lsp_document_symbol_cb()
3336
return function(bufnr)
@@ -63,7 +66,8 @@ function M.make_lsp_document_symbol_cb()
6366
end
6467
end
6568

66-
---@param num_of_lines integer
69+
---Use the lines above and below the current line as the query messages.
70+
---@param num_of_lines integer The number of lines to include in the query.
6771
---@return VectorCode.QueryCallback
6872
function M.make_surrounding_lines_cb(num_of_lines)
6973
return function(bufnr)

0 commit comments

Comments
 (0)