Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions doc/VectorCode-API.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ This function queries VectorCode and returns an array of results.
})
<

- `query_message`string or a list of strings, the query messages;
- `opts`The following are the available options for this function (see |VectorCode-API-`setup(opts?)`| for details):
- `query_message`: string or a list of strings, the query messages;
- `opts`: The following are the available options for this function (see |VectorCode-API-`setup(opts?)`| for details):

>lua
{
Expand All @@ -71,7 +71,7 @@ This function queries VectorCode and returns an array of results.
}
<

- `callback`a callback function that takes the result of the retrieval as the
- `callback`: a callback function that takes the result of the retrieval as the
only parameter. If this is set, the `query` function will be non-blocking and
runs in an async manner. In this case, it doesn’t return any value and
retrieval results can only be accessed by this callback function.
Expand Down Expand Up @@ -118,7 +118,7 @@ project. See the CLI manual for details <./cli.md>.
require("vectorcode").check()
<

The following are the available options for this function: - `check_item`Only
The following are the available options for this function: - `check_item`: Only
supports `"config"` at the moment. Checks if a project-local config is present.
Return value: `true` if passed, `false` if failed.

Expand Down Expand Up @@ -201,25 +201,25 @@ This function registers a buffer to be cached by VectorCode.
})
<

The following are the available options for this function: - `bufnr`buffer
number. Default: `0` (current buffer); - `opts`accepts a lua table with the
following keys: - `project_root`a string of the path that overrides the
The following are the available options for this function: - `bufnr`: buffer
number. Default: `0` (current buffer); - `opts`: accepts a lua table with the
following keys: - `project_root`: a string of the path that overrides the
detected project root. Default: `nil`. This is mostly intended to use with the
|VectorCode-API-user-command|, and you probably should not use this directly in
your config. **If you’re using the LSP backend and did not specify this
value, it will be automatically detected based on .vectorcode or .git. If this
fails, LSP backend will not work**; - `exclude_this`whether to exclude the file
you’re editing. Default: `true`; - `n_query`number of retrieved documents.
Default: `1`; - `debounce`debounce time in milliseconds. Default: `10`; -
`notify`whether to show notifications when a query is completed. Default:
`false`; - `query_cb``fun(bufnr: integer):string|string[]`, a callback function
that accepts the buffer ID and returns the query message(s). Default:
`require("vectorcode.utils").make_surrounding_lines_cb(-1)`. See
fails, LSP backend will not work**; - `exclude_this`: whether to exclude the
file you’re editing. Default: `true`; - `n_query`: number of retrieved
documents. Default: `1`; - `debounce`: debounce time in milliseconds. Default:
`10`; - `notify`: whether to show notifications when a query is completed.
Default: `false`; - `query_cb`: `fun(bufnr: integer):string|string[]`, a
callback function that accepts the buffer ID and returns the query message(s).
Default: `require("vectorcode.utils").make_surrounding_lines_cb(-1)`. See
|VectorCode-API-this-section| for a list of built-in query callbacks; -
`events`list of autocommand events that triggers the query. Default:
`{"BufWritePost", "InsertEnter", "BufReadPost"}`; - `run_on_register`whether to
run the query when the buffer is registered. Default: `false`; -
`single_job`boolean. If this is set to `true`, there will only be one running
`events`: list of autocommand events that triggers the query. Default:
`{"BufWritePost", "InsertEnter", "BufReadPost"}`; - `run_on_register`: whether
to run the query when the buffer is registered. Default: `false`; -
`single_job`: boolean. If this is set to `true`, there will only be one running
job for each buffer, and when a new job is triggered, the last-running job will
be cancelled. Default: `false`.

Expand All @@ -232,10 +232,10 @@ This function queries VectorCode from cache.
local query_results = cacher_backend.query_from_cache(0, {notify=false})
<

The following are the available options for this function: - `bufnr`buffer
number. Default: current buffer; - `opts`accepts a lua table with the following
keys: - `notify`boolean, whether to show notifications when a query is
completed. Default: `false`;
The following are the available options for this function: - `bufnr`: buffer
number. Default: current buffer; - `opts`: accepts a lua table with the
following keys: - `notify`: boolean, whether to show notifications when a query
is completed. Default: `false`;

Return value: an array of results. Each item of the array is in the format of
`{path="path/to/your/code.lua", document="document content"}`.
Expand All @@ -254,17 +254,18 @@ project.
)
<

The following are the available options for this function: - `check_item`any
The following are the available options for this function: - `check_item`: any
check that works with `vectorcode check` command. If not set, it defaults to
`"config"`; - `on_success`a callback function that is called when the check
passes; - `on_failure`a callback function that is called when the check fails.
`"config"`; - `on_success`: a callback function that is called when the check
passes; - `on_failure`: a callback function that is called when the check
fails.


CACHER_BACKEND.BUF_IS_REGISTERED(BUFNR?) ~

This function checks if a buffer has been registered with VectorCode.

The following are the available options for this function: - `bufnr`buffer
The following are the available options for this function: - `bufnr`: buffer
number. Default: current buffer. Return value: `true` if registered, `false`
otherwise.

Expand All @@ -276,7 +277,7 @@ slightly different from `buf_is_registered`, because it does not guarantee
VectorCode is actively caching the content of the buffer. It is the same as
`buf_is_registered && not is_paused`.

The following are the available options for this function: - `bufnr`buffer
The following are the available options for this function: - `bufnr`: buffer
number. Default: current buffer. Return value: `true` if enabled, `false`
otherwise.

Expand All @@ -288,8 +289,8 @@ Returns the number of running jobs in the background.

CACHER_BACKEND.MAKE_PROMPT_COMPONENT(BUFNR?, COMPONENT_CB?) ~

Compile the retrieval results into a string. Parameters: - `bufnr`buffer
number. Default: current buffer; - `component_cb`a callback function that
Compile the retrieval results into a string. Parameters: - `bufnr`: buffer
number. Default: current buffer; - `component_cb`: a callback function that
formats each retrieval result, so that you can customise the control token,
etc. for the component. The default is the following:

Expand All @@ -299,8 +300,8 @@ etc. for the component. The default is the following:
end
<

`make_prompt_component` returns a table with 2 keys: - `count`number of
retrieved documents; - `content`The retrieval results concatenated together
`make_prompt_component` returns a table with 2 keys: - `count`: number of
retrieved documents; - `content`: The retrieval results concatenated together
into a string. Each result is formatted by `component_cb`.


Expand All @@ -311,15 +312,15 @@ takes the buffer ID as the only parameter, and return a string or a list of
strings. The `vectorcode.utils` module provides the following callback
constructor for you to play around with it, but you can easily build your own!

- `require("vectorcode.utils").make_surrounding_lines_cb(line_count)`returns a
- `require("vectorcode.utils").make_surrounding_lines_cb(line_count)`: returns a
callback that uses `line_count` lines around the cursor as the query. When
`line_count` is negative, it uses the full buffer;
- `require("vectorcode.utils").make_lsp_document_symbol_cb()`returns a
- `require("vectorcode.utils").make_lsp_document_symbol_cb()`: returns a
callback which uses the `textDocument/documentSymbol` method to retrieve a
list of symbols in the current document. This will fallback to
`make_surrounding_lines_cb(-1)` when there’s no LSP that supports the
`documentSymbol` method;
- `require("vectorcode.utils").make_changes_cb(max_num)`returns a callback
- `require("vectorcode.utils").make_changes_cb(max_num)`: returns a callback
that fetches `max_num` unique items from the `:changes` list. This will also
fallback to `make_surrounding_lines_cb(-1)`. The default value for `max_num`
is 50.
Expand Down
Loading
Loading