|
26 | 26 | ---@param params? string |
27 | 27 | ---@return table |
28 | 28 | local function resolve(chat, var_config, params) |
29 | | - local splits = vim.split(var_config.callback, ".", { plain = true }) |
30 | | - local path = table.concat(splits, ".", 1, #splits - 1) |
31 | | - local variable = splits[#splits] |
32 | | - |
33 | | - local ok, module = pcall(require, "codecompanion." .. path .. "." .. variable) |
34 | | - |
35 | | - local init = { |
36 | | - Chat = chat, |
37 | | - config = var_config, |
38 | | - params = params, |
39 | | - } |
| 29 | + if type(var_config.callback) == "string" then |
| 30 | + local splits = vim.split(var_config.callback, ".", { plain = true }) |
| 31 | + local path = table.concat(splits, ".", 1, #splits - 1) |
| 32 | + local variable = splits[#splits] |
| 33 | + |
| 34 | + local ok, module = pcall(require, "codecompanion." .. path .. "." .. variable) |
| 35 | + |
| 36 | + local init = { |
| 37 | + Chat = chat, |
| 38 | + config = var_config, |
| 39 | + params = params, |
| 40 | + } |
| 41 | + |
| 42 | + -- User is using a custom callback |
| 43 | + if not ok then |
| 44 | + log:trace("Calling variable: %s", path .. "." .. variable) |
| 45 | + return require(path .. "." .. variable).new(init):output() |
| 46 | + end |
40 | 47 |
|
41 | | - -- User is using a custom callback |
42 | | - if not ok then |
43 | 48 | log:trace("Calling variable: %s", path .. "." .. variable) |
44 | | - return require(path .. "." .. variable).new(init):output() |
| 49 | + return module.new(init):output() |
45 | 50 | end |
46 | 51 |
|
47 | | - log:trace("Calling variable: %s", path .. "." .. variable) |
48 | | - return module.new(init):output() |
| 52 | + return require("codecompanion.strategies.chat.variables.user") |
| 53 | + .new({ |
| 54 | + Chat = chat, |
| 55 | + config = var_config, |
| 56 | + params = params, |
| 57 | + }) |
| 58 | + :output() |
49 | 59 | end |
50 | 60 |
|
51 | 61 | ---@class CodeCompanion.Variables |
@@ -92,6 +102,8 @@ function Variables:parse(chat, message) |
92 | 102 | local var_config = self.vars[var] |
93 | 103 | log:debug("Variable found: %s", var) |
94 | 104 |
|
| 105 | + var_config["name"] = var |
| 106 | + |
95 | 107 | if (var_config.opts and var_config.opts.contains_code) and not config.can_send_code() then |
96 | 108 | log:warn("Sending of code has been disabled") |
97 | 109 | goto continue |
|
0 commit comments