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
  • Loading branch information
deathbeam committed Dec 5, 2024
1 parent d8db2c6 commit c4c0fb1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 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,18 @@ 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'))
M.open(config)

if not config.headless then
M.open(config)
end
config = vim.tbl_deep_extend('force', state.chat.config, config or {})
config = vim.tbl_deep_extend('force', M.config, config or {})

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

vim.diagnostic.reset(vim.api.nvim_create_namespace('copilot_diagnostics'))

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

0 comments on commit c4c0fb1

Please sign in to comment.