diff --git a/README.md b/README.md index a5fd09cf..5f3d46c7 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ See @deathbeam for [configuration](https://github.com/deathbeam/dotfiles/blob/ma - `:CopilotChatOpen` - Open chat window - `:CopilotChatClose` - Close chat window - `:CopilotChatToggle` - Toggle chat window +- `:CopilotChatStop` - Stop current copilot output - `:CopilotChatReset` - Reset chat window - `:CopilotChatSave ?` - Save chat history to file - `:CopilotChatLoad ?` - Load chat history from file diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 992d748b..c01e21da 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -351,7 +351,7 @@ function M.ask(prompt, config, source) M.open(config, source, true) if config.clear_chat_on_new_prompt then - M.reset(true) + M.stop(true, true) end state.last_system_prompt = system_prompt @@ -442,10 +442,11 @@ function M.ask(prompt, config, source) }) end ---- Reset the chat window and show the help message. -function M.reset(no_insert) +--- Stop current copilot output and optionally reset the chat ten show the help message. +---@param reset boolean +function M.stop(reset, no_insert) state.response = nil - local stopped = state.copilot:reset() + local stopped = reset and state.copilot:reset() or state.copilot:stop() local wrap = vim.schedule if not stopped then wrap = function(fn) @@ -454,7 +455,9 @@ function M.reset(no_insert) end wrap(function() - state.chat:clear() + if reset then + state.chat:clear() + end append(M.config.question_header .. M.config.separator .. '\n\n') state.chat:finish() state.chat:follow() @@ -465,6 +468,11 @@ function M.reset(no_insert) end) end +--- Reset the chat window and show the help message. +function M.reset() + M.stop(true) +end + --- Save the chat history to a file. ---@param name string? ---@param history_path string? @@ -818,6 +826,7 @@ function M.setup(config) vim.api.nvim_create_user_command('CopilotChatOpen', M.open, { force = true }) vim.api.nvim_create_user_command('CopilotChatClose', M.close, { force = true }) vim.api.nvim_create_user_command('CopilotChatToggle', M.toggle, { force = true }) + vim.api.nvim_create_user_command('CopilotChatStop', M.stop, { force = true }) vim.api.nvim_create_user_command('CopilotChatReset', M.reset, { force = true }) local function complete_load()