From 2fca000ac40302a60f96abb28790070916bd2bf6 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Thu, 5 Dec 2024 10:56:05 +0100 Subject: [PATCH] fix: correct chat config handling 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 --- lua/CopilotChat/init.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 7f0e4902..51704a3f 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -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() @@ -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)