|
30 | 30 |
|
31 | 31 | ---@class VectorCode.CodeCompanion.PromptFactory.Opts |
32 | 32 | ---@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 |
34 | 34 | ---Paths to the files in the local directory to be added to the database. |
35 | 35 | --- |
36 | 36 | ---These should either be absolute paths, or relative to the project root. |
37 | | ----@field file_patterns string[] |
| 37 | +---@field file_patterns string[]|(fun():string[]) |
38 | 38 | ---See https://codecompanion.olimorris.dev/extending/prompts.html#recipe-2-using-context-in-your-prompts |
39 | 39 | --- |
40 | 40 | ---Note: If a system prompt is set here, your default chat system prompt will be ignored. |
|
47 | 47 |
|
48 | 48 | ---@param opts VectorCode.CodeCompanion.PromptFactory.Opts |
49 | 49 | 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 | + |
50 | 60 | 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), |
52 | 63 | string.format("`%s` is not a valid directory.", opts.project_root) |
53 | 64 | ) |
54 | 65 | assert( |
| 66 | + ---@diagnostic disable-next-line: param-type-mismatch |
55 | 67 | opts.file_patterns ~= nil and (not vim.tbl_isempty(opts.file_patterns)), |
56 | 68 | "Recieved empty path specs." |
57 | 69 | ) |
|
0 commit comments