1
1
# NeoVim Plugin
2
+
2
3
> [ !NOTE]
3
4
> This plugin depends on the CLI tool. Please go through
4
5
> [ the CLI documentation] ( ../cli/README.md ) and make sure the VectorCode CLI is working
18
19
* [ Integrations] ( #integrations )
19
20
* [ milanglacier/minuet-ai.nvim] ( #milanglacierminuet-ainvim )
20
21
* [ olimorris/codecompanion.nvim] ( #olimorriscodecompanionnvim )
22
+ * [ Tools] ( #tools )
23
+ * [ Prompt Library] ( #prompt-library )
21
24
* [ CopilotC-Nvim/CopilotChat.nvim] ( #copilotc-nvimcopilotchatnvim )
22
25
* [ Setup] ( #setup )
23
26
* [ Configuration Options] ( #configuration-options )
@@ -155,6 +158,7 @@ or change the value of `async_opts.n_query` in the `setup` function
155
158
156
159
[ ![ asciicast] ( https://asciinema.org/a/8WP8QJHNAR9lEllZSSx3poLPD.svg )] ( https://asciinema.org/a/8WP8QJHNAR9lEllZSSx3poLPD?t=3 )
157
160
161
+ #### Tools
158
162
The following requires VectorCode 0.7+ and a recent version of CodeCompanion.nvim.
159
163
160
164
The CodeCompanion extension will register the following tools:
@@ -176,7 +180,7 @@ option explained below.
176
180
177
181
``` lua
178
182
--- @module " vectorcode"
179
- opts = {
183
+ require ( " codecompanion " ). setup ( {
180
184
extensions = {
181
185
vectorcode = {
182
186
--- @type VectorCode.CodeCompanion.ExtensionOpts
@@ -211,15 +215,15 @@ opts = {
211
215
enabled = false ,
212
216
adapter = nil ,
213
217
query_augmented = true ,
214
- }
218
+ },
215
219
},
216
220
files_ls = {},
217
- files_rm = {}
218
- }
221
+ files_rm = {},
222
+ },
219
223
},
220
224
},
221
- }
222
- }
225
+ },
226
+ })
223
227
```
224
228
225
229
The following are the common options that all tools supports:
@@ -277,6 +281,58 @@ The `query` tool contains the following extra config options:
277
281
query so that when the LLM decide what information to include, it _ may_ be
278
282
able to avoid omitting stuff related to query.
279
283
284
+ #### Prompt Library
285
+
286
+ On VectorCode 0.7.16+ and CodeCompanion.nvim 17.20.0+, VectorCode also provides a
287
+ customisable prompt library that helps you RAG local directories. The presets
288
+ provided by VectorCode are available
289
+ [ here] ( ../../lua/vectorcode/integrations/codecompanion/prompts/presets.lua ) , which
290
+ you can refer to if you wish to build local RAG APPs with CodeCompanion.nvim and
291
+ VectorCode.
292
+
293
+ ``` lua
294
+ require (" codecompanion" ).setup ({
295
+ extensions = {
296
+ vectorcode = {
297
+ --- @type VectorCode.CodeCompanion.ExtensionOpts
298
+ opts = {
299
+ --- @type table<string , VectorCode.CodeCompanion.PromptFactory.Opts>
300
+ prompt_library = {
301
+ {
302
+ [" Neovim Tutor" ] = {
303
+ -- this is for demonstration only.
304
+ -- "Neovim Tutor" is shipped with this plugin already,
305
+ -- and you don't need to add it in the config
306
+ -- unless you're not happy with the defaults.
307
+ project_root = vim .env .VIMRUNTIME ,
308
+ file_patterns = { " lua/**/*.lua" , " doc/**/*.txt" },
309
+ -- system_prompt = ...,
310
+ -- user_prompt = ...,
311
+ },
312
+ },
313
+ },
314
+ },
315
+ },
316
+ },
317
+ })
318
+ ```
319
+
320
+ The ` prompt_library ` option is a mapping of prompt name (` string ` ) to a lua table
321
+ (type annotation available) that contains some information used to generate the
322
+ embeddings:
323
+
324
+ - ` project_root ` : ` string ` , the path to the directory (for example,
325
+ ` /usr/share/nvim/runtime/ ` );
326
+ - ` file_patterns ` : ` string[] ` , file name patterns that defines files to be vectorised.
327
+ You should either use absolute paths or relative paths from the project root;
328
+ - ` system_prompt ` and ` user_prompt ` : ` string|fun(context:table):string|nil ` :
329
+ These options allow you to customise the prompts. See
330
+ [ codecompanion.nvim documentation] ( https://codecompanion.olimorris.dev/extending/prompts#recipe-2-using-context-in-your-prompts )
331
+ if you want to use a function here that build the prompts from the context.
332
+
333
+ The first time will take some extra time for computing the embeddings, but the
334
+ subsequent runs should be a lot faster.
335
+
280
336
### [ CopilotC-Nvim/CopilotChat.nvim] ( https://github.com/CopilotC-Nvim/CopilotChat.nvim )
281
337
282
338
[ CopilotC-Nvim/CopilotChat.nvim] ( https://github.com/CopilotC-Nvim/CopilotChat.nvim )
@@ -290,13 +346,14 @@ contextual information about your codebase to enhance Copilot's responses. Add t
290
346
to your CopilotChat configuration:
291
347
292
348
``` lua
293
- local vectorcode_ctx = require (' vectorcode.integrations.copilotchat' ).make_context_provider ({
294
- prompt_header = " Here are relevant files from the repository:" , -- Customize header text
295
- prompt_footer = " \n Consider this context when answering:" , -- Customize footer text
296
- skip_empty = true , -- Skip adding context when no files are retrieved
297
- })
298
-
299
- require (' CopilotChat' ).setup ({
349
+ local vectorcode_ctx =
350
+ require (" vectorcode.integrations.copilotchat" ).make_context_provider ({
351
+ prompt_header = " Here are relevant files from the repository:" , -- Customize header text
352
+ prompt_footer = " \n Consider this context when answering:" , -- Customize footer text
353
+ skip_empty = true , -- Skip adding context when no files are retrieved
354
+ })
355
+
356
+ require (" CopilotChat" ).setup ({
300
357
-- Your other CopilotChat options...
301
358
302
359
contexts = {
@@ -308,10 +365,10 @@ require('CopilotChat').setup({
308
365
prompts = {
309
366
Explain = {
310
367
prompt = " Explain the following code in detail:\n $input" ,
311
- context = {" selection" , " vectorcode" }, -- Add vectorcode to the context
368
+ context = { " selection" , " vectorcode" }, -- Add vectorcode to the context
312
369
},
313
370
-- Other prompts...
314
- }
371
+ },
315
372
})
316
373
```
317
374
@@ -339,7 +396,7 @@ The integration includes caching to avoid sending duplicate context to the LLM,
339
396
You can configure VectorCode to be part of your sticky prompts, ensuring every conversation includes relevant codebase context automatically:
340
397
341
398
``` lua
342
- require (' CopilotChat' ).setup ({
399
+ require (" CopilotChat" ).setup ({
343
400
-- Your other CopilotChat options...
344
401
345
402
sticky = {
@@ -360,8 +417,8 @@ cached retrieval results.
360
417
``` lua
361
418
tabline = {
362
419
lualine_y = {
363
- require (" vectorcode.integrations" ).lualine (opts )
364
- }
420
+ require (" vectorcode.integrations" ).lualine (opts ),
421
+ },
365
422
}
366
423
```
367
424
` opts ` is a table with the following configuration option:
@@ -386,7 +443,7 @@ tabline = {
386
443
end
387
444
end ,
388
445
},
389
- }
446
+ },
390
447
}
391
448
```
392
449
This will further delay the loading of VectorCode to the moment you (or one of
@@ -533,12 +590,9 @@ vim.api.nvim_create_autocmd("LspAttach", {
533
590
callback = function ()
534
591
local bufnr = vim .api .nvim_get_current_buf ()
535
592
cacher .async_check (" config" , function ()
536
- cacher .register_buffer (
537
- bufnr ,
538
- {
539
- n_query = 10 ,
540
- }
541
- )
593
+ cacher .register_buffer (bufnr , {
594
+ n_query = 10 ,
595
+ })
542
596
end , nil )
543
597
end ,
544
598
desc = " Register buffer for VectorCode" ,
0 commit comments