-
Notifications
You must be signed in to change notification settings - Fork 3
Chat history "persistence" #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ericdallo
merged 5 commits into
editor-code-assistant:main
from
tamercuba:feature/chat-history+clear-chat
Mar 22, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3243019
feat: preserve chat history across sidebar toggles and add EcaChatCle…
tamercuba d22bab0
fix: address PR review feedback for chat history preservation
tamercuba edbaa32
fix: cleanup nui Split autocmds on toggle and encapsulate EcaChatClea…
tamercuba 48e3e4d
fix: reset full chat state and always unmount old Split on clear
tamercuba 939f2e6
fix: reset last user message when clearing chat
tamercuba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,238 @@ | ||
| local MiniTest = require("mini.test") | ||
| local eq = MiniTest.expect.equality | ||
| local child = MiniTest.new_child_neovim() | ||
|
|
||
| local function flush(ms) | ||
| vim.uv.sleep(ms or 120) | ||
| child.api.nvim_eval("1") | ||
| end | ||
|
|
||
| local function setup_helpers() | ||
| _G.fill_chat = function() | ||
| local sidebar = require("eca").get() | ||
| local chat = sidebar.containers.chat | ||
| vim.api.nvim_buf_set_lines(chat.bufnr, 0, -1, false, { "hello", "world", "foo" }) | ||
| end | ||
|
|
||
| _G.get_chat_lines = function() | ||
| local sidebar = require("eca").get() | ||
| if not sidebar then | ||
| return nil | ||
| end | ||
| local chat = sidebar.containers and sidebar.containers.chat | ||
| if not chat or not vim.api.nvim_buf_is_valid(chat.bufnr) then | ||
| return nil | ||
| end | ||
| return vim.api.nvim_buf_get_lines(chat.bufnr, 0, -1, false) | ||
| end | ||
|
|
||
| _G.chat_has_old_content = function() | ||
| for _, line in ipairs(_G.get_chat_lines() or {}) do | ||
| if line == "hello" or line == "world" or line == "foo" then | ||
| return true | ||
| end | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| _G.get_sidebar_flags = function() | ||
| local sidebar = require("eca").get() | ||
| if not sidebar then | ||
| return nil | ||
| end | ||
| return { | ||
| welcome_message_applied = sidebar._welcome_message_applied, | ||
| force_welcome = sidebar._force_welcome, | ||
| } | ||
| end | ||
| end | ||
|
|
||
| local function setup_env(preserve_chat_history) | ||
| child.lua( | ||
| [[ | ||
| local Eca = require("eca") | ||
| Eca.setup({ | ||
| behavior = { | ||
| auto_start_server = false, | ||
| auto_set_keymaps = false, | ||
| preserve_chat_history = ..., | ||
| }, | ||
| }) | ||
| local tab = vim.api.nvim_get_current_tabpage() | ||
| Eca._init(tab) | ||
| Eca.open_sidebar({}) | ||
| ]], | ||
| { preserve_chat_history } | ||
| ) | ||
| child.lua_func(setup_helpers) | ||
| end | ||
|
|
||
| local T = MiniTest.new_set({ | ||
| hooks = { | ||
| pre_case = function() | ||
| child.restart({ "-u", "scripts/minimal_init.lua" }) | ||
| end, | ||
| post_once = child.stop, | ||
| }, | ||
| }) | ||
|
|
||
| -- EcaChatClear --------------------------------------------------------------- | ||
|
|
||
| T["EcaChatClear"] = MiniTest.new_set() | ||
|
|
||
| T["EcaChatClear"]["command is registered"] = function() | ||
| setup_env(false) | ||
| local commands = child.lua_get("vim.api.nvim_get_commands({})") | ||
| eq(type(commands.EcaChatClear), "table") | ||
| eq(commands.EcaChatClear.name, "EcaChatClear") | ||
| end | ||
|
|
||
| T["EcaChatClear"]["clears chat buffer when sidebar is open"] = function() | ||
| setup_env(false) | ||
| flush(200) | ||
|
|
||
| child.lua("_G.fill_chat()") | ||
| eq(#child.lua_get("_G.get_chat_lines()"), 3) | ||
|
|
||
| child.cmd("EcaChatClear") | ||
|
|
||
| eq(child.lua_get("_G.get_chat_lines()"), { "" }) | ||
| end | ||
|
|
||
| T["EcaChatClear"]["works without error when buffer is already empty"] = function() | ||
| setup_env(false) | ||
| flush(200) | ||
|
|
||
| child.lua([[ | ||
| local sidebar = require("eca").get() | ||
| vim.api.nvim_buf_set_lines(sidebar.containers.chat.bufnr, 0, -1, false, {}) | ||
| ]]) | ||
|
|
||
| child.cmd("EcaChatClear") | ||
|
|
||
| eq(child.lua_get("_G.get_chat_lines()"), { "" }) | ||
| end | ||
|
|
||
| T["EcaChatClear"]["clears hidden buffer when sidebar is closed with preserve=true"] = function() | ||
| setup_env(true) | ||
| flush(200) | ||
|
|
||
| child.lua("_G.fill_chat()") | ||
| child.lua([[require("eca").close_sidebar()]]) | ||
| flush(100) | ||
|
|
||
| child.cmd("EcaChatClear") | ||
|
|
||
| eq(child.lua_get("_G.get_chat_lines()"), { "" }) | ||
| end | ||
|
|
||
| T["EcaChatClear"]["buffer stays cleared on reopen with preserve=true"] = function() | ||
| setup_env(true) | ||
| flush(200) | ||
|
|
||
| child.lua("_G.fill_chat()") | ||
| child.lua([[require("eca").close_sidebar()]]) | ||
| flush(100) | ||
|
|
||
| child.cmd("EcaChatClear") | ||
|
|
||
| eq(child.lua_get("_G.get_chat_lines()"), { "" }) | ||
|
|
||
| child.lua([[require("eca").open_sidebar({})]]) | ||
| flush(200) | ||
|
|
||
| eq(child.lua_get("_G.chat_has_old_content()"), false) | ||
| end | ||
|
|
||
| T["EcaChatClear"]["is a no-op when sidebar is closed and buffer was destroyed (preserve=false)"] = function() | ||
| -- With preserve=false, closing the sidebar destroys the buffer, so there is | ||
| -- nothing for EcaChatClear to clear. The important guarantee is that the | ||
| -- command does not raise an error in this state. | ||
| setup_env(false) | ||
| flush(200) | ||
|
|
||
| child.lua("_G.fill_chat()") | ||
| child.lua([[require("eca").close_sidebar()]]) | ||
| flush(100) | ||
|
|
||
| local ok = child.lua_get("pcall(vim.cmd, 'EcaChatClear')") | ||
| eq(ok, true) | ||
| end | ||
|
|
||
| T["EcaChatClear"]["marks welcome as applied and clears force_welcome after clear"] = function() | ||
| setup_env(false) | ||
| flush(200) | ||
|
|
||
| child.lua("_G.fill_chat()") | ||
| child.cmd("EcaChatClear") | ||
|
|
||
| local flags = child.lua_get("_G.get_sidebar_flags()") | ||
| eq(flags.welcome_message_applied, true) | ||
| eq(flags.force_welcome, false) | ||
| end | ||
|
|
||
| T["EcaChatClear"]["is idempotent when called twice"] = function() | ||
| setup_env(false) | ||
| flush(200) | ||
|
|
||
| child.lua("_G.fill_chat()") | ||
| child.cmd("EcaChatClear") | ||
| child.cmd("EcaChatClear") | ||
|
|
||
| eq(child.lua_get("_G.get_chat_lines()"), { "" }) | ||
| end | ||
|
|
||
| -- preserve_chat_history toggle cycle ----------------------------------------- | ||
|
|
||
| T["preserve_chat_history"] = MiniTest.new_set() | ||
|
|
||
| T["preserve_chat_history"]["reuses same bufnr and keeps content across close/open"] = function() | ||
| setup_env(true) | ||
| flush(200) | ||
|
|
||
| child.lua("_G.fill_chat()") | ||
| local bufnr_before = child.lua_get("require('eca').get().containers.chat.bufnr") | ||
|
|
||
| child.lua([[require("eca").close_sidebar()]]) | ||
| flush(100) | ||
| child.lua([[require("eca").open_sidebar({})]]) | ||
| flush(200) | ||
|
|
||
| local bufnr_after = child.lua_get("require('eca').get().containers.chat.bufnr") | ||
| eq(bufnr_before, bufnr_after) | ||
| eq(child.lua_get("_G.chat_has_old_content()"), true) | ||
| end | ||
|
|
||
| T["preserve_chat_history"]["does not leak buffers across repeated toggles"] = function() | ||
| setup_env(true) | ||
| flush(200) | ||
|
|
||
| local buf_count_before = child.lua_get("#vim.api.nvim_list_bufs()") | ||
|
|
||
| for _ = 1, 5 do | ||
| child.lua([[require("eca").close_sidebar()]]) | ||
| flush(100) | ||
| child.lua([[require("eca").open_sidebar({})]]) | ||
| flush(200) | ||
| end | ||
|
|
||
| local buf_count_after = child.lua_get("#vim.api.nvim_list_bufs()") | ||
| -- Allow at most 1 extra buffer (nui internals), but definitely not 5+ | ||
| eq(buf_count_after - buf_count_before <= 1, true) | ||
| end | ||
|
|
||
| T["preserve_chat_history"]["content is lost when preserve is disabled"] = function() | ||
| setup_env(false) | ||
| flush(200) | ||
|
|
||
| child.lua("_G.fill_chat()") | ||
|
|
||
| child.lua([[require("eca").close_sidebar()]]) | ||
| flush(100) | ||
| child.lua([[require("eca").open_sidebar({})]]) | ||
| flush(200) | ||
|
|
||
| eq(child.lua_get("_G.chat_has_old_content()"), false) | ||
| end | ||
|
|
||
| return T |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.