Skip to content

Commit e51cb24

Browse files
committed
feat(nvim): Add VectorCode integration for Neovim help files
1 parent 0046e64 commit e51cb24

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

lua/codecompanion/_extensions/vectorcode/init.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ local M = {
5252
opts.tool_opts = merge_tool_opts(opts.tool_opts)
5353
logger.info("Received codecompanion extension opts:\n", opts)
5454
local cc_config = require("codecompanion.config").config
55-
local cc_integration = require("vectorcode.integrations").codecompanion.chat
55+
local cc_integration = require("vectorcode.integrations").codecompanion
56+
local cc_chat_integration = cc_integration.chat
5657
for _, sub_cmd in pairs(valid_tools) do
5758
local tool_name = string.format("vectorcode_%s", sub_cmd)
5859
if cc_config.strategies.chat.tools[tool_name] ~= nil then
@@ -73,7 +74,7 @@ local M = {
7374
else
7475
cc_config.strategies.chat.tools[tool_name] = {
7576
description = string.format("Run VectorCode %s tool", sub_cmd),
76-
callback = cc_integration.make_tool(sub_cmd, opts.tool_opts[sub_cmd]),
77+
callback = cc_chat_integration.make_tool(sub_cmd, opts.tool_opts[sub_cmd]),
7778
opts = { requires_approval = opts.tool_opts[sub_cmd].requires_approval },
7879
}
7980
logger.info(string.format("%s tool has been created.", tool_name))
@@ -105,6 +106,14 @@ local M = {
105106
tools = included_tools,
106107
}
107108
end
109+
110+
for _, prompt in pairs(cc_integration.prompts) do
111+
if type(prompt) == "function" then
112+
---@diagnostic disable-next-line: cast-local-type
113+
prompt = prompt()
114+
end
115+
cc_config.prompt_library[prompt.name] = prompt.prompts
116+
end
108117
end),
109118
}
110119

lua/vectorcode/integrations/codecompanion/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ return {
1616
end
1717
end,
1818
},
19+
prompts = {
20+
require("vectorcode.integrations.codecompanion.prompts.nvim"),
21+
},
1922
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---@module "codecompanion"
2+
3+
return require("vectorcode.config").check_cli_wrap(function()
4+
local constants = require("codecompanion.config").config.constants
5+
local rtp = vim.fs.normalize(vim.env.VIMRUNTIME)
6+
7+
if not rtp then
8+
return error("Failed to locate the neovim runtime!", vim.log.levels.ERROR)
9+
end
10+
local stat = vim.uv.fs_stat(rtp)
11+
if not stat or stat.type ~= "directory" then
12+
return error(
13+
string.format(
14+
"$VIMRUNTIME is %s, which is not a valid directory to be accessed.",
15+
rtp
16+
),
17+
vim.log.levels.ERROR
18+
)
19+
end
20+
return {
21+
name = "Neovim Assistant",
22+
prompts = {
23+
strategy = "chat",
24+
description = "Use VectorCode to index and query from neovim documentation and lua runtime.",
25+
26+
prompts = {
27+
{
28+
role = constants.SYSTEM_ROLE,
29+
content = string.format(
30+
[[You are an neovim expert.
31+
You will be given tools to index and query from the neovim runtime library.
32+
This will include lua APIs for the neovim runtime and documentation for the neovim build that the user is running.
33+
Use the tools to explain the user's questions related to neovim.
34+
The runtime files are stored in `%s`.
35+
You can ONLY use the vectorcode tools to interact with these files or directory.
36+
DO NOT attempt to read from or write into this directory.
37+
]],
38+
rtp
39+
),
40+
},
41+
{
42+
role = constants.USER_ROLE,
43+
content = string.format(
44+
[[
45+
You are given the @{vectorcode_vectorise} and @{vectorcode_query} tools.
46+
Vectorrise all lua files and `*.txt` files under this directory using the `vectorcode_vectorise` tool. Use wildcards to match all lua and `txt` files. Use absolute paths when supplying paths to the vectorcode_vectorise tool;
47+
Use `%s` as the value of the `project_root` argument;
48+
When you're done, I'll be asking you questions related to these documents.
49+
Use the vectorcode_query tool to query from the project root and answer my question.
50+
]],
51+
rtp,
52+
rtp
53+
),
54+
},
55+
},
56+
},
57+
}
58+
end)

0 commit comments

Comments
 (0)