Skip to content

Commit

Permalink
fix: correct chat config handling
Browse files Browse the repository at this point in the history
When opening chat and asking questions, ensure proper config inheritance
by deep extending chat state config with provided config and global config.
Also move config handling before early returns to maintain consistency.

Closes #676

Signed-off-by: Tomas Slusny <[email protected]>
  • Loading branch information
deathbeam committed Dec 5, 2024
1 parent d8db2c6 commit 2fca000
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ function M.open(config)
end

config = vim.tbl_deep_extend('force', M.config, config or {})
if config.headless then
return
end

utils.return_to_normal_mode()
state.chat:open(config)
state.chat:follow()
Expand Down Expand Up @@ -676,18 +680,17 @@ end
---@param prompt string?
---@param config CopilotChat.config.shared?
function M.ask(prompt, config)
config = vim.tbl_deep_extend('force', M.config, config or {})
vim.diagnostic.reset(vim.api.nvim_create_namespace('copilot_diagnostics'))

if not config.headless then
M.open(config)
end
M.open(config)

prompt = vim.trim(prompt or '')
if prompt == '' then
return
end

vim.diagnostic.reset(vim.api.nvim_create_namespace('copilot_diagnostics'))
config = vim.tbl_deep_extend('force', state.chat.config, config or {})
config = vim.tbl_deep_extend('force', M.config, config or {})

if not config.headless then
if config.clear_chat_on_new_prompt then
M.stop(true)
Expand Down

0 comments on commit 2fca000

Please sign in to comment.