Chat history "persistence"#59
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an opt-in mechanism to keep the chat buffer alive when closing/toggling the ECA sidebar, plus a new EcaChatClear command to explicitly reset the chat content.
Changes:
- Introduces
behavior.preserve_chat_history(defaultfalse) to preserve chat content across sidebar close/reopen. - Updates sidebar window/buffer lifecycle to reuse the existing chat buffer when preservation is enabled.
- Adds
:EcaChatClearand corresponding tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
lua/eca/config.lua |
Adds the preserve_chat_history config default. |
lua/eca/sidebar.lua |
Implements window-only closing and chat buffer reuse; adjusts refresh behavior when preservation is enabled. |
lua/eca/commands.lua |
Registers :EcaChatClear to clear the chat buffer and reset welcome flags. |
tests/test_chat_clear.lua |
Adds test coverage for :EcaChatClear across open/closed sidebar states and preservation modes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lua/eca/config.lua
Outdated
| auto_start_server = false, -- Automatically start server on setup | ||
| auto_download = true, -- Automatically download server if not found | ||
| show_status_updates = true, -- Show status updates in notifications | ||
| preserve_chat_history = false, -- When true, chat history is preserved after toggling/closing the chat window |
| @@ -332,6 +348,13 @@ function M:_create_containers() | |||
| }), | |||
| win_options = base_win_options, | |||
| }) | |||
|
|
|||
| if existing_chat_bufnr then | |||
| pcall(vim.api.nvim_buf_delete, self.containers.chat.bufnr, { force = true }) | |||
| self.containers.chat.bufnr = existing_chat_bufnr | |||
| Logger.debug("Reusing existing chat buffer: " .. existing_chat_bufnr) | |||
| end | |||
lua/eca/sidebar.lua
Outdated
| if preserve then | ||
| -- Close only the window, keep the buffer alive | ||
| pcall(vim.api.nvim_win_close, container.winid, true) | ||
| container.winid = nil | ||
| else |
lua/eca/sidebar.lua
Outdated
| function M:_refresh_container_content() | ||
| local preserve = Config.behavior and Config.behavior.preserve_chat_history | ||
| -- Refresh content without full setup | ||
| if self.containers.chat then | ||
| self:_set_welcome_content() | ||
| if not preserve then | ||
| self:_set_welcome_content() | ||
| end |
| vim.api.nvim_create_user_command("EcaChatClear", function() | ||
| local sidebar = require("eca").get() | ||
| if sidebar then | ||
| sidebar._welcome_message_applied = false | ||
| sidebar._force_welcome = false | ||
| local chat = sidebar.containers and sidebar.containers.chat | ||
| if chat and chat.bufnr and vim.api.nvim_buf_is_valid(chat.bufnr) then | ||
| vim.api.nvim_buf_set_lines(chat.bufnr, 0, -1, false, {}) | ||
| end | ||
| end |
|
FYI @joaopluigi |
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “preserve chat history” mode so toggling/closing the sidebar keeps the underlying chat buffer alive, and introduces an :EcaChatClear command to explicitly clear the chat.
Changes:
- Add
behavior.preserve_chat_history(defaultfalse) to optionally keep the chat buffer across sidebar close/open cycles. - Update sidebar close/open logic to retain and reuse the existing chat buffer when preservation is enabled.
- Add
:EcaChatClearplus a new MiniTest suite covering clear behavior and persistence/leak checks.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lua/eca/sidebar.lua |
Implements “windows-only” close behavior and chat-buffer reuse when preserve_chat_history is enabled. |
lua/eca/config.lua |
Adds the preserve_chat_history default config flag. |
lua/eca/commands.lua |
Registers :EcaChatClear to clear the chat buffer and adjust welcome flags. |
tests/test_chat_clear.lua |
New tests for :EcaChatClear and buffer persistence across toggles. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| local preserve = Config.behavior and Config.behavior.preserve_chat_history | ||
|
|
||
| for name, container in pairs(self.containers) do | ||
| if container and container.winid and vim.api.nvim_win_is_valid(container.winid) then | ||
| container:unmount() | ||
| -- Keep the container reference but mark window as invalid | ||
| container.winid = nil | ||
| if preserve and name == "chat" then | ||
| -- Close only the window, keep the buffer alive | ||
| pcall(vim.api.nvim_win_close, container.winid, true) | ||
| container.winid = nil | ||
| else | ||
| container:unmount() | ||
| -- Keep the container reference but mark window as invalid | ||
| container.winid = nil | ||
| end |
| sidebar._welcome_message_applied = true | ||
| sidebar._force_welcome = false | ||
| local chat = sidebar.containers and sidebar.containers.chat | ||
| if chat and chat.bufnr and vim.api.nvim_buf_is_valid(chat.bufnr) then |
| sidebar._welcome_message_applied = true | ||
| sidebar._force_welcome = false |
Problem
Closing or toggling the sidebar to reclaim screen space for code, a REPL buffer, or any other window would wipe the ongoing conversation. Reopening the sidebar always started fresh, which made the toggle gesture impractical during an active session.
Solution
When
behavior.preserve_chat_history = true, closing the sidebar only closes the windows. The underlying chat buffer is kept alive and reattached the next time the sidebar opens, so the conversation continues exactly where it was left off.A new
EcaChatClearcommand is provided to explicitly reset the chat when needed.The flag defaults to
falseto preserve the existing behavior for anyone updating the plugin. If the maintainers prefers making persistence the default and dropping the flag, that change is straightforward.Config
Before / After