diff --git a/doc/VectorCode-API.txt b/doc/VectorCode-API.txt index 54fc295e..7bd3530a 100644 --- a/doc/VectorCode-API.txt +++ b/doc/VectorCode-API.txt @@ -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 { @@ -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. @@ -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. @@ -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`. @@ -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"}`. @@ -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. @@ -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. @@ -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: @@ -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`. @@ -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. diff --git a/doc/VectorCode-cli.txt b/doc/VectorCode-cli.txt index 06bbd1f1..a6680e11 100644 --- a/doc/VectorCode-cli.txt +++ b/doc/VectorCode-cli.txt @@ -94,14 +94,14 @@ If you need to install multiple dependency group (for |VectorCode-cli-lsp| or INSTALL FROM SOURCE ~ To install from source, either `git clone` this repository and run `uv tool -install `, or use `pipx` +install `, or use `pipx`: >bash pipx install git+https://github.com/Davidyz/VectorCode < -MIGRATIONFROM PIPX ~ +MIGRATION FROM PIPX ~ The motivation behind the change from `pipx` to `uv tool` is mainly the performance. The caching mechanism in uv makes it a lot faster than `pipx` for @@ -310,7 +310,7 @@ comma in the config file, as well as writing comments (`//`). This can be very useful if you’re experimenting with the configs. The JSON configuration file may hold the following values: - -`embedding_function`string, one of the embedding functions supported by +`embedding_function`: string, one of the embedding functions supported by Chromadb (find more here and here ). For example, @@ -318,31 +318,31 @@ Chromadb supports Ollama as `chromadb.utils.embedding_functions.OllamaEmbeddingFunction`, and the corresponding value for `embedding_function` would be `OllamaEmbeddingFunction`. Default: `SentenceTransformerEmbeddingFunction`; - -`embedding_params`dictionary, stores whatever initialisation parameters your +`embedding_params`: dictionary, stores whatever initialisation parameters your embedding function takes. For `OllamaEmbeddingFunction`, if you set `embedding_params` to: `json { "url": "http://127.0.0.1:11434/api/embeddings", "model_name": "nomic-embed-text" }` Then the embedding function object will be initialised as `OllamaEmbeddingFunction(url="http://127.0.0.1:11434/api/embeddings", -model_name="nomic-embed-text")`. Default: `{}`; - `embedding_dims`integer or +model_name="nomic-embed-text")`. Default: `{}`; - `embedding_dims`: integer or `null`, the number of dimensions to truncate the embeddings to. _Make sure your model supports Matryoshka Representation Learning (MRL) before using this._ Learn more about MRL here . -When set to `null` (or unset), the embeddings won’t be truncated; - -`db_url`string, the url that points to the Chromadb server. VectorCode will -start an HTTP server for Chromadb at a randomly picked free port on `localhost` -if your configured `http://host:port` is not accessible. Default: -`http://127.0.0.1:8000`; - `db_path`string, Path to local persistent database. -If you didn’t set up a standalone Chromadb server, this is where the files -for your database will be stored. Default: -`~/.local/share/vectorcode/chromadb/`; - `db_log_path`string, path to the +When set to `null` (or unset), the embeddings won’t be truncated; - `db_url`: +string, the url that points to the Chromadb server. VectorCode will start an +HTTP server for Chromadb at a randomly picked free port on `localhost` if your +configured `http://host:port` is not accessible. Default: +`http://127.0.0.1:8000`; - `db_path`: string, Path to local persistent +database. If you didn’t set up a standalone Chromadb server, this is where +the files for your database will be stored. Default: +`~/.local/share/vectorcode/chromadb/`; - `db_log_path`: string, path to the _directory_ where the built-in chromadb server will write the log to. Default: -`~/.local/share/vectorcode/`; - `chunk_size`integer, the maximum number of +`~/.local/share/vectorcode/`; - `chunk_size`: integer, the maximum number of characters per chunk. A larger value reduces the number of items in the database, and hence accelerates the search, but at the cost of potentially truncated data and lost information. Default: `2500`. To disable chunking, set -it to a negative number; - `overlap_ratio`float between 0 and 1, the ratio of +it to a negative number; - `overlap_ratio`: float between 0 and 1, the ratio of overlapping/shared content between 2 adjacent chunks. A larger ratio improves the coherence of chunks, but at the cost of increasing number of entries in the database and hence slowing down the search. Default: `0.2`. _Starting from @@ -351,33 +351,33 @@ automatically detect. It uses pygments to guess the language from filename, and tree-sitter-language-pack to fetch the correct parser. overlap_ratio has no effects when treesitter works. If VectorCode fails to find an appropriate parser, it’ll fallback to the legacy naive parser, in which case -overlap_ratio works exactly in the same way as before;_ - -`query_multiplier`integer, when you use the `query` command to retrieve `n` -documents, VectorCode will check `n * query_multiplier` chunks and return at -most `n` documents. A larger value of `query_multiplier` guarantees the return -of `n` documents, but with the risk of including too many less-relevant chunks -that may affect the document selection. Default: `-1` (any negative value means -selecting documents based on all indexed chunks); - `reranker`string, the -reranking method to use. Currently supports `NaiveReranker` (sort chunks by the -"distance" between the embedding vectors) and `CrossEncoderReranker` (using -sentence-transformers cross-encoder +overlap_ratio works exactly in the same way as before;_ - `query_multiplier`: +integer, when you use the `query` command to retrieve `n` documents, VectorCode +will check `n * query_multiplier` chunks and return at most `n` documents. A +larger value of `query_multiplier` guarantees the return of `n` documents, but +with the risk of including too many less-relevant chunks that may affect the +document selection. Default: `-1` (any negative value means selecting documents +based on all indexed chunks); - `reranker`: string, the reranking method to +use. Currently supports `NaiveReranker` (sort chunks by the "distance" between +the embedding vectors) and `CrossEncoderReranker` (using sentence-transformers +cross-encoder ). -- `reranker_params`dictionary, similar to `embedding_params`. The options +- `reranker_params`: dictionary, similar to `embedding_params`. The options passed to the reranker class constructor. For `CrossEncoderReranker`, these are the options passed to the `CrossEncoder` class. For example, if you want to use a non-default model, you can use the following: `json { "reranker_params": { "model_name_or_path": "your_model_here" -} }` - `db_settings`dictionary, works in a similar way to `embedding_params`, +} }` - `db_settings`: dictionary, works in a similar way to `embedding_params`, but for Chromadb client settings so that you can configure authentication for remote Chromadb ; - -`hnsw`a dictionary of hnsw settings +`hnsw`: a dictionary of hnsw settings that may improve the query performances or avoid runtime errors during queries. **It’s recommended to re-vectorise the collection after modifying these options, because some of the options can only be set during collection creation.** -Example (and default): `json5 "hnsw": { "hnsw:M": 64, }` - -`filetype_map``dict[str, list[str]]`, a dictionary where keys are language name +Example (and default): `json5 "hnsw": { "hnsw:M": 64, }` - `filetype_map`: +`dict[str, list[str]]`, a dictionary where keys are language name and values are lists of Python regex patterns that will match file extensions. @@ -386,8 +386,8 @@ parser for certain file types for which the language parser cannot be correctly identified (e.g., `.phtml` files containing both php and html). Example configuration: `json5 "filetype_map": { "php": ["^phtml$"] }` -- `chunk_filters``dict[str, list[str]]`, a dictionary where the keys are language - name +- `chunk_filters`: `dict[str, list[str]]`, a dictionary where the keys are + language name and values are lists of Python regex patterns that will match chunks to be @@ -401,7 +401,7 @@ configuration: `json5 "filetype_map": { "php": ["^phtml$"] }` "*": ["^[^a-zA-Z0-9]+$"], } < -- `encoding`string, alternative encoding used for this project. By default this +- `encoding`: string, alternative encoding used for this project. By default this project uses utf8. When this is set, VectorCode will decode files with the specified encoding, unless you choose to override this with the `--encoding` command line flag. You can also set this to `_auto`, which uses @@ -561,7 +561,7 @@ You may run `vectorcode check` command to check whether VectorCode is properly installed and configured for your project. This currently supports only 1 check: -- `config`checks whether a project-local configuration directory exists. +- `config`: checks whether a project-local configuration directory exists. Prints the project-root if successful, otherwise returns a non-zero exit code. Running `vectorcode check config` is faster than running `vectorcode query @@ -650,7 +650,7 @@ supports OpenVINO backend for supported GPU. Run `uv install 'vectorcode[intel]'` which will bundle the relevant libraries when you install VectorCode. After that, you will need to configure `SentenceTransformer` to use `openvino` backend. In your -`config.json`, set `backend` key in `embedding_params` to `"openvino"` +`config.json`, set `backend` key in `embedding_params` to `"openvino"`: >json { @@ -660,7 +660,7 @@ need to configure `SentenceTransformer` to use `openvino` backend. In your } < -Thiswill run the embedding model on your GPU. This is supported even for some +This will run the embedding model on your GPU. This is supported even for some integrated GPUs. When using the default embedding function, any options inside the @@ -730,11 +730,11 @@ distinguish between chunks. These are the same IDs used in the database. VECTORCODE VECTORISE The output is in JSON format. It contains a dictionary with the following -fields: - `"add"`number of added documents; - `"update"`number of updated -documents; - `"removed"`number of removed documents; - `"skipped"`number of +fields: - `"add"`: number of added documents; - `"update"`: number of updated +documents; - `"removed"`: number of removed documents; - `"skipped"`: number of skipped documents (because it’s empty or its hash matches the metadata saved -in the database); - `"failed"`number of documents that failed to be vectorised. -This is usually due to encoding issues. +in the database); - `"failed"`: number of documents that failed to be +vectorised. This is usually due to encoding issues. VECTORCODE LS @@ -753,14 +753,14 @@ A JSON array of collection information of the following format will be printed: } < -- `"project_root"`the path to the `project-root`; -- `"user"`your nix username, which are automatically added when vectorising to +- `"project_root"`: the path to the `project-root`; +- `"user"`: your nix username, which are automatically added when vectorising to avoid collision; -- `"hostname"`your nix hostname. The purpose of this field is the same as the +- `"hostname"`: your nix hostname. The purpose of this field is the same as the `"user"`; -- `"collection_name"`the unique identifier for the project used in the database; -- `"size"`number of chunks stored in the database; -- `"num_files"`number of files that have been vectorised in the project. +- `"collection_name"`: the unique identifier for the project used in the database; +- `"size"`: number of chunks stored in the database; +- `"num_files"`: number of files that have been vectorised in the project. VECTORCODE FILES LS @@ -837,12 +837,12 @@ an open protocol that standardizes how applications provide context to LLMs. VectorCode provides an experimental implementation that provides the following features: -- `ls`list local collections, similar to the `ls` subcommand in the CLI; -- `query`query from a given collection, similar to the `query` subcommand in +- `ls`: list local collections, similar to the `ls` subcommand in the CLI; +- `query`: query from a given collection, similar to the `query` subcommand in the CLI; -- `vectorise`vectorise files into a given project; -- `files_ls`show files that have been indexed for the current project; -- `files_rm`remove some files from the database for a project. +- `vectorise`: vectorise files into a given project; +- `files_ls`: show files that have been indexed for the current project; +- `files_rm`: remove some files from the database for a project. To try it out, install the `vectorcode[mcp]` dependency group and the MCP server is available in the shell as `vectorcode-mcp-server`. diff --git a/doc/VectorCode.txt b/doc/VectorCode.txt index 99040dcf..7b558788 100644 --- a/doc/VectorCode.txt +++ b/doc/VectorCode.txt @@ -185,13 +185,13 @@ The following requires VectorCode 0.7+ and a recent version of CodeCompanion.nvim. The CodeCompanion extension will register the following tools: - -`@{vectorcode_ls}`an equivalent of `vectorcode ls` command that shows the -indexed projects on your system; - `@{vectorcode_query}`an equivalent of +`@{vectorcode_ls}`: an equivalent of `vectorcode ls` command that shows the +indexed projects on your system; - `@{vectorcode_query}`: an equivalent of `vectorcode query` command that searches from a project; - -`@{vectorcode_vectorise}`an equivalent of `vectorcode vectorise` command that -adds files to the database; - `@{vectorcode_files_ls}`an equivalent of +`@{vectorcode_vectorise}`: an equivalent of `vectorcode vectorise` command that +adds files to the database; - `@{vectorcode_files_ls}`: an equivalent of `vectorcode files ls` command that gives a list of indexed files in a project; -- `@{vectorcode_files_rm}`an equivalent of `vectorcode files rm` command that +- `@{vectorcode_files_rm}`: an equivalent of `vectorcode files rm` command that removes files from a collection. By default, it’ll also create a tool group called `@{vectorcode_toolbox}`, @@ -249,15 +249,15 @@ the `include_in_toolbox` option explained below. The following are the common options that all tools supports: -- `use_lsp`whether to use the LSP backend to run the queries. Using LSP +- `use_lsp`: whether to use the LSP backend to run the queries. Using LSP provides some insignificant performance boost and a nice notification pop-up if you’re using fidget.nvim . Default: `true` if `async_backend` is set to `"lsp"` in `setup()`. Otherwise, it’ll be `false`; -- `requires_approval`whether CodeCompanion.nvim asks for your approval before +- `requires_approval`: whether CodeCompanion.nvim asks for your approval before executing the tool call. Default: `false` for `ls` and `query`; `true` for `vectorise`; -- `include_in_toolbox`whether this tool should be included in +- `include_in_toolbox`: whether this tool should be included in `vectorcode_toolbox`. Default: `true` for `query`, `vectorise` and `ls`, `false` for `files_*`. @@ -266,38 +266,38 @@ individually, or use the `["*"]` key to specify the default settings for all tools. If you’ve set both the default settings (via `["*"]`) and the individual settings for a tool, the individual settings take precedence. -The `query` tool contains the following extra config options: - -`chunk_mode`boolean, whether the VectorCode backend should return chunks or -full documents. Default: `false`; - `max_num` and `default_num`If they’re set -to integers, they represent the default and maximum allowed number of results -returned by VectorCode (regardless of document or chunk mode). They can also be -set to tables with 2 keys: `document` and `chunk`. In this case, their values -would be used for the corresponding mode. You may ask the LLM to request a -different number of chunks or documents, but they’ll be capped by the values -in `max_num`. Default: See the sample snippet above. Negative values for -`max_num` means unlimited. - `no_duplicate`boolean, whether the query calls -should attempt to exclude files that has been retrieved and provided in the -previous turns of the current chat. This helps saving tokens and increase the -chance of retrieving the correct files when the previous retrievals fail to do -so. Default: `true`. - `summarise`optional summarisation for the retrieval -results. This is a table with the following keys: - `enabled`This can either be -a boolean that toggles summarisation on/off completely, or a function that +The `query` tool contains the following extra config options: - `chunk_mode`: +boolean, whether the VectorCode backend should return chunks or full documents. +Default: `false`; - `max_num` and `default_num`: If they’re set to integers, +they represent the default and maximum allowed number of results returned by +VectorCode (regardless of document or chunk mode). They can also be set to +tables with 2 keys: `document` and `chunk`. In this case, their values would be +used for the corresponding mode. You may ask the LLM to request a different +number of chunks or documents, but they’ll be capped by the values in +`max_num`. Default: See the sample snippet above. Negative values for `max_num` +means unlimited. - `no_duplicate`: boolean, whether the query calls should +attempt to exclude files that has been retrieved and provided in the previous +turns of the current chat. This helps saving tokens and increase the chance of +retrieving the correct files when the previous retrievals fail to do so. +Default: `true`. - `summarise`: optional summarisation for the retrieval +results. This is a table with the following keys: - `enabled`: This can either +be a boolean that toggles summarisation on/off completely, or a function that accepts the `CodeCompanion.Chat` object and the raw query results as the 2 paramters and returns a boolean. When it’s the later, it’ll be evaluated for every tool call. This allows you to write some custom logic to dynamically turn summarisation on and off. _When the summarisation is enabled, but you find the summaries not informative enough, you can tell the LLM to disable the summarisation during the chat so that it sees the raw information_; - -`adapter`See CodeCompanion documentation +`adapter`: See CodeCompanion documentation . -When not provided, it’ll use the chat adapter; - `system_prompt`When set to a -string, this will be used as the system prompt for the summarisation model. +When not provided, it’ll use the chat adapter; - `system_prompt`: When set to +a string, this will be used as the system prompt for the summarisation model. When set to a function, it’ll be called with the default system prompt as the only parameter, and it should return a string that will be used as a system prompt. This allows you to append/prepend things to the default system prompt; -- `query_augmented`boolean, whether the system prompt should contain the query -so that when the LLM decide what information to include, it _may_ be able to -avoid omitting stuff related to query. +- `query_augmented`: boolean, whether the system prompt should contain the +query so that when the LLM decide what information to include, it _may_ be able +to avoid omitting stuff related to query. PROMPT LIBRARY @@ -340,12 +340,12 @@ The `prompt_library` option is a mapping of prompt name (`string`) to a lua table (type annotation available) that contains some information used to generate the embeddings: -- `project_root``string`, the path to the directory (for example, +- `project_root`: `string`, the path to the directory (for example, `/usr/share/nvim/runtime/`); -- `file_patterns``string[]`, file name patterns that defines files to be vectorised. +- `file_patterns`: `string[]`, file name patterns that defines files to be vectorised. You should either use absolute paths or relative paths from the project root; -- `system_prompt` and `user_prompt``string|fun(context:table):string|nil` - Theseoptions allow you to customise the prompts. See +- `system_prompt` and `user_prompt`: `string|fun(context:table):string|nil`: + These options allow you to customise the prompts. See codecompanion.nvim documentation if you want to use a function here that build the prompts from the context. @@ -399,10 +399,10 @@ CONFIGURATION OPTIONS The `make_context_provider` function accepts these options: -- `prompt_header`Text that appears before the code context (default: "The following are relevant files from the repository. Use them as extra context for helping with code completion and understanding:") -- `prompt_footer`Text that appears after the code context (default: "and provide a strategy with examples about: ") -- `skip_empty`Whether to skip adding context when no files are retrieved (default: true) -- `format_file`A function that formats each retrieved file (takes a file result object and returns formatted string) +- `prompt_header`: Text that appears before the code context (default: "The following are relevant files from the repository. Use them as extra context for helping with code completion and understanding:") +- `prompt_footer`: Text that appears after the code context (default: "and provide a strategy with examples about: ") +- `skip_empty`: Whether to skip adding context when no files are retrieved (default: true) +- `format_file`: A function that formats each retrieved file (takes a file result object and returns formatted string) USAGE TIPS @@ -456,9 +456,9 @@ cached retrieval results. } < -`opts` is a table with the following configuration option: - -`show_job_count`boolean, whether to show the number of running jobs for the -buffer. Default: `false`. +`opts` is a table with the following configuration option: - `show_job_count`: +boolean, whether to show the number of running jobs for the buffer. Default: +`false`. This will, however, start VectorCode when lualine starts (which usually means when neovim starts). If this bothers you, you can use the following snippet: @@ -573,32 +573,33 @@ This function initialises the VectorCode client and sets up some default < The following are the available options for the parameter of this function: - -`cli_cmds`A table to customize the CLI command names / paths used by the -plugin. Supported key: - `vectorcode`The command / path to use for the main CLI -tool. Default: `"vectorcode"`. - `n_query`number of retrieved documents. A -large number gives a higher chance of including the right file, but with the +`cli_cmds`: A table to customize the CLI command names / paths used by the +plugin. Supported key: - `vectorcode`: The command / path to use for the main +CLI tool. Default: `"vectorcode"`. - `n_query`: number of retrieved documents. +A large number gives a higher chance of including the right file, but with the risk of saturating the context window and getting truncated. Default: `1`; - -`notify`whether to show notifications when a query is completed. Default: -`true`; - `timeout_ms`timeout in milliseconds for the query operation. Applies -to synchronous API only. Default: `5000` (5 seconds); - `exclude_this`whether -to exclude the file you’re editing. Setting this to `false` may lead to an -outdated version of the current file being sent to the LLM as the prompt, and -can lead to generations with outdated information; - `async_opts`default +`notify`: whether to show notifications when a query is completed. Default: +`true`; - `timeout_ms`: timeout in milliseconds for the query operation. +Applies to synchronous API only. Default: `5000` (5 seconds); - `exclude_this`: +whether to exclude the file you’re editing. Setting this to `false` may lead +to an outdated version of the current file being sent to the LLM as the prompt, +and can lead to generations with outdated information; - `async_opts`: default options used when registering buffers. See -|VectorCode-`register_buffer(bufnr?,-opts?)`| for details; - `async_backend`the -async backend to use, currently either `"default"` or `"lsp"`. Default: -`"default"`; - `on_setup`some actions that can be registered to run when -`setup` is called. Supported keys: - `update`if `true`, the plugin will run -`vectorcode update` on startup to update the embeddings; - `lsp`if `true`, the -plugin will try to start the LSP server on startup so that you won’t need to -wait for the server loading when making your first request. _Please pay extra -attention on lazy-loading so that the LSP server won’t be started without a -buffer to be attached to (see here)._ - `sync_log_env_var``boolean`. If true, -this plugin will automatically set the `VECTORCODE_LOG_LEVEL` environment -variable for LSP or cmd processes started within your neovim session when -logging is turned on for this plugin. Use at caution because the non-LSP CLI -write all logs to stderr, which _may_ make this plugin VERY verbose. See -|VectorCode-debugging-and-logging| for details on how to turn on logging. +|VectorCode-`register_buffer(bufnr?,-opts?)`| for details; - `async_backend`: +the async backend to use, currently either `"default"` or `"lsp"`. Default: +`"default"`; - `on_setup`: some actions that can be registered to run when +`setup` is called. Supported keys: - `update`: if `true`, the plugin will run +`vectorcode update` on startup to update the embeddings; - `lsp`: if `true`, +the plugin will try to start the LSP server on startup so that you won’t need +to wait for the server loading when making your first request. _Please pay +extra attention on lazy-loading so that the LSP server won’t be started +without a buffer to be attached to (see here)._ - `sync_log_env_var`: +`boolean`. If true, this plugin will automatically set the +`VECTORCODE_LOG_LEVEL` environment variable for LSP or cmd processes started +within your neovim session when logging is turned on for this plugin. Use at +caution because the non-LSP CLI write all logs to stderr, which _may_ make this +plugin VERY verbose. See |VectorCode-debugging-and-logging| for details on how +to turn on logging. You may notice that a lot of options in `async_opts` are the same as the other options in the top-level of the main option table. This is because the diff --git a/lua/vectorcode/cacher/init.lua b/lua/vectorcode/cacher/init.lua index 3fb94cae..08f7a1ac 100644 --- a/lua/vectorcode/cacher/init.lua +++ b/lua/vectorcode/cacher/init.lua @@ -18,19 +18,37 @@ return { return end check_item = check_item or "config" - jobrunner.run_async({ "check", check_item }, function(result, error, code, signal) - local out = { - stdout = table.concat(vim.iter(result):flatten(math.huge):totable()), - stderr = table.concat(vim.iter(error):flatten(math.huge):totable()), - code = code, - signal = signal, - } - if out.code == 0 and type(on_success) == "function" then - vim.schedule_wrap(on_success)(out) - elseif out.code ~= 0 and type(on_failure) == "function" then - vim.schedule_wrap(on_failure)(out) - end - end, 0) + jobrunner.run_async( + { "check", check_item }, + function(result, _error, code, signal) + local out_msg = nil + if type(result) == "table" and #result > 0 then + out_msg = table.concat(vim.iter(result):flatten(math.huge):totable()) + elseif type(result) == "string" then + out_msg = result + end + + local err_msg = nil + if type(_error) == "table" and #_error > 0 then + err_msg = table.concat(vim.iter(_error):flatten(math.huge):totable()) + elseif type(_error) == "string" then + out_msg = _error + end + + local out = { + stdout = out_msg, + stderr = err_msg, + code = code, + signal = signal, + } + if out.code == 0 and type(on_success) == "function" then + vim.schedule_wrap(on_success)(out) + elseif out.code ~= 0 and type(on_failure) == "function" then + vim.schedule_wrap(on_failure)(out) + end + end, + 0 + ) end, }, } diff --git a/lua/vectorcode/init.lua b/lua/vectorcode/init.lua index c9c4c474..af923498 100644 --- a/lua/vectorcode/init.lua +++ b/lua/vectorcode/init.lua @@ -190,7 +190,7 @@ function M.check(check_item, stdout_cb) if type(stdout_cb) == "function" then stdout_cb({ stdout = utils.flatten_table_to_string(result), - stderr = utils.flatten_table_to_string(error), + stderr = utils.flatten_table_to_string(error, "Unknown error."), code = code, signal = signal, }) diff --git a/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua b/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua index dcd9e80a..4b0f0d89 100644 --- a/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua @@ -43,7 +43,7 @@ return function(opts) cb({ status = "success", data = result }) else if type(error) == "table" then - error = utils.flatten_table_to_string(error) + error = utils.flatten_table_to_string(error, "Unknown error.") end cb({ status = "error", diff --git a/lua/vectorcode/integrations/codecompanion/ls_tool.lua b/lua/vectorcode/integrations/codecompanion/ls_tool.lua index d90c8e79..e6f0dec6 100644 --- a/lua/vectorcode/integrations/codecompanion/ls_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/ls_tool.lua @@ -45,7 +45,7 @@ return function(opts) cb({ status = "success", data = result }) else if type(error) == "table" then - error = utils.flatten_table_to_string(error) + error = utils.flatten_table_to_string(error, "Unknown error.") end cb({ status = "error", diff --git a/lua/vectorcode/integrations/codecompanion/prompts/init.lua b/lua/vectorcode/integrations/codecompanion/prompts/init.lua index 5b8d296f..29daf5c2 100644 --- a/lua/vectorcode/integrations/codecompanion/prompts/init.lua +++ b/lua/vectorcode/integrations/codecompanion/prompts/init.lua @@ -131,14 +131,12 @@ Here's my question: vc_config.notify_opts ) elseif err ~= nil then - err = utils.flatten_table_to_string(err) - if err ~= "" then - vim.schedule_wrap(vim.notify)( - err, - vim.log.levels.WARN, - vc_config.notify_opts - ) - end + err = utils.flatten_table_to_string(err, "Unknown error.") + vim.schedule_wrap(vim.notify)( + err, + vim.log.levels.WARN, + vc_config.notify_opts + ) end end ) diff --git a/lua/vectorcode/integrations/codecompanion/query_tool.lua b/lua/vectorcode/integrations/codecompanion/query_tool.lua index 4a267cb1..f7e95679 100644 --- a/lua/vectorcode/integrations/codecompanion/query_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/query_tool.lua @@ -600,7 +600,7 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES vim.inspect(stderr) ) ) - stderr = utils.flatten_table_to_string(stderr) + stderr = utils.flatten_table_to_string(stderr, "Unknown error.") if string.find(stderr, "InvalidCollectionException") then if cmd.project_root then tools.chat:add_tool_output( diff --git a/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua b/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua index addba165..731d81c2 100644 --- a/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua @@ -125,7 +125,7 @@ The value should be one of the following: vim.inspect(stderr) ) ) - stderr = utils.flatten_table_to_string(stderr) + stderr = utils.flatten_table_to_string(stderr, "Unknown error.") tools.chat:add_tool_output( self, string.format("**VectorCode `vectorise` Tool: %s", stderr) diff --git a/lua/vectorcode/utils.lua b/lua/vectorcode/utils.lua index c1ede61c..089dbcec 100644 --- a/lua/vectorcode/utils.lua +++ b/lua/vectorcode/utils.lua @@ -174,10 +174,12 @@ function M.is_directory(f) end ---@param t table|string|nil +---@param fallback string? ---@return string -M.flatten_table_to_string = function(t) +M.flatten_table_to_string = function(t, fallback) + fallback = fallback or "" if t == nil then - return "" + return fallback end if type(t) == "string" then return t @@ -193,7 +195,7 @@ M.flatten_table_to_string = function(t) :totable() if #flattened == 0 then - return "Unknown error occurred" + return fallback end return table.concat(flattened, "\n")