diff --git a/lua/CopilotChat/chat.lua b/lua/CopilotChat/chat.lua index c7cd0376..ecfea7d6 100644 --- a/lua/CopilotChat/chat.lua +++ b/lua/CopilotChat/chat.lua @@ -34,11 +34,10 @@ local function create_buf() return bufnr end -local Chat = class(function(self, name, on_buf_create) +local Chat = class(function(self, on_buf_create) self.on_buf_create = on_buf_create - self.bufnr = create_buf() - self.on_buf_create(self.bufnr) - self.spinner = Spinner(self.bufnr, name) + self.bufnr = nil + self.spinner = nil self.winnr = nil end) @@ -55,9 +54,14 @@ function Chat:validate() return end self.bufnr = create_buf() - self.on_buf_create(self.bufnr) - self.spinner.bufnr = self.bufnr + if not self.spinner then + self.spinner = Spinner(self.bufnr, 'copilot-chat') + else + self.spinner.bufnr = self.bufnr + end + self:close() + self.on_buf_create(self.bufnr) end function Chat:last() diff --git a/lua/CopilotChat/diff.lua b/lua/CopilotChat/diff.lua index d498ed92..b1497356 100644 --- a/lua/CopilotChat/diff.lua +++ b/lua/CopilotChat/diff.lua @@ -40,9 +40,7 @@ local Diff = class(function(self, on_buf_create, help) self.current = nil self.ns = vim.api.nvim_create_namespace('copilot-diff') self.mark_ns = vim.api.nvim_create_namespace('copilot-diff-mark') - self.bufnr = create_buf() - self.on_buf_create(self.bufnr) - + self.bufnr = nil vim.api.nvim_set_hl(self.ns, '@diff.plus', { bg = blend_color_with_neovim_bg('DiffAdd', 20) }) vim.api.nvim_set_hl(self.ns, '@diff.minus', { bg = blend_color_with_neovim_bg('DiffDelete', 20) }) vim.api.nvim_set_hl(self.ns, '@diff.delta', { bg = blend_color_with_neovim_bg('DiffChange', 20) }) diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 985d5de3..a45ea5ba 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -434,7 +434,7 @@ function M.setup(config) .. "' to accept diff." ) - state.chat = Chat(plugin_name, function(bufnr) + state.chat = Chat(function(bufnr) if M.config.mappings.complete then vim.keymap.set('i', M.config.mappings.complete, complete, { buffer = bufnr }) end @@ -495,12 +495,13 @@ function M.setup(config) end end, { buffer = bufnr }) end + + M.reset() end) tiktoken.setup() debuginfo.setup() M.debug(M.config.debug) - M.reset() for name, prompt in pairs(M.prompts(true)) do vim.api.nvim_create_user_command('CopilotChat' .. name, function(args)