Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/CopilotChat/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
---@field blend number?

---@class CopilotChat.config.Shared
---@field system_prompt string?
---@field system_prompt string|fun(source: CopilotChat.source):string|nil
---@field model string?
---@field tools string|table<string>|nil
---@field sticky string|table<string>|nil
Expand Down
23 changes: 23 additions & 0 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ local function list_prompts()
return prompts_to_use
end

--- Resolve system prompt - handle both string and function types
---@param system_prompt string|function|nil
---@return string?
local function resolve_system_prompt(system_prompt)
if not system_prompt then
return nil
end

if type(system_prompt) == 'function' then
local ok, result = pcall(system_prompt)
if not ok then
log.warn('Failed to resolve system prompt function: ' .. result)
return nil
end
return result
end

return system_prompt
end

--- Finish writing to chat buffer.
---@param start_of_chat boolean?
local function finish(start_of_chat)
Expand Down Expand Up @@ -503,6 +523,9 @@ function M.resolve_prompt(prompt, config)
config = vim.tbl_deep_extend('force', M.config, config or {})
config, prompt = resolve(config, prompt or '')

-- Resolve system prompt (handle functions)
config.system_prompt = resolve_system_prompt(config.system_prompt, state.source)

if config.system_prompt then
for name, prompt in pairs(prompts_to_use) do
if prompt.system_prompt then
Expand Down
Loading