Skip to content

Chat history "persistence"#59

Open
tamercuba wants to merge 2 commits intoeditor-code-assistant:mainfrom
tamercuba:feature/chat-history+clear-chat
Open

Chat history "persistence"#59
tamercuba wants to merge 2 commits intoeditor-code-assistant:mainfrom
tamercuba:feature/chat-history+clear-chat

Conversation

@tamercuba
Copy link

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 EcaChatClear command is provided to explicitly reset the chat when needed.

The flag defaults to false to 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

require("eca").setup({
  behavior = {
    preserve_chat_history = true,
  },
})

Before / After

Before After
before after

Copilot AI review requested due to automatic review settings March 13, 2026 20:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (default false) to preserve chat content across sidebar close/reopen.
  • Updates sidebar window/buffer lifecycle to reuse the existing chat buffer when preservation is enabled.
  • Adds :EcaChatClear and 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.

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
Comment on lines 329 to +356
@@ -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
Comment on lines +164 to +168
if preserve then
-- Close only the window, keep the buffer alive
pcall(vim.api.nvim_win_close, container.winid, true)
container.winid = nil
else
Comment on lines +656 to +662
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
Comment on lines +550 to +559
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
@ericdallo
Copy link
Member

FYI @joaopluigi

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (default false) 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 :EcaChatClear plus 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.

Comment on lines +160 to +172
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
Comment on lines +553 to +556
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
Comment on lines +553 to +554
sidebar._welcome_message_applied = true
sidebar._force_welcome = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants