Skip to content

Commit a9c0106

Browse files
author
Zhe Yu
committed
feat(nvim): allow function type for project_root and file_patterns
1 parent 0af447b commit a9c0106

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

  • lua/vectorcode/integrations/codecompanion/prompts

lua/vectorcode/integrations/codecompanion/prompts/init.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ end
3030

3131
---@class VectorCode.CodeCompanion.PromptFactory.Opts
3232
---@field name string? human-readable name of this prompt
33-
---@field project_root string project_root of the files to be added to the database
33+
---@field project_root string|(fun():string) project_root of the files to be added to the database
3434
---Paths to the files in the local directory to be added to the database.
3535
---
3636
---These should either be absolute paths, or relative to the project root.
37-
---@field file_patterns string[]
37+
---@field file_patterns string[]|(fun():string[])
3838
---See https://codecompanion.olimorris.dev/extending/prompts.html#recipe-2-using-context-in-your-prompts
3939
---
4040
---Note: If a system prompt is set here, your default chat system prompt will be ignored.
@@ -47,11 +47,23 @@ end
4747

4848
---@param opts VectorCode.CodeCompanion.PromptFactory.Opts
4949
function M.register_prompt(opts)
50+
opts = vim.deepcopy(opts)
51+
52+
if type(opts.project_root) == "function" then
53+
opts.project_root = opts.project_root()
54+
end
55+
56+
if type(opts.file_patterns) == "function" then
57+
opts.file_patterns = opts.file_patterns()
58+
end
59+
5060
assert(
51-
utils.is_directory(opts.project_root),
61+
---@diagnostic disable-next-line: param-type-mismatch
62+
type(opts.project_root) == "string" and utils.is_directory(opts.project_root),
5263
string.format("`%s` is not a valid directory.", opts.project_root)
5364
)
5465
assert(
66+
---@diagnostic disable-next-line: param-type-mismatch
5567
opts.file_patterns ~= nil and (not vim.tbl_isempty(opts.file_patterns)),
5668
"Recieved empty path specs."
5769
)

0 commit comments

Comments
 (0)