From f2cc878878b6a09da4ff358961fb5a4f4ce56948 Mon Sep 17 00:00:00 2001 From: ushmz <44394399+ushmz@users.noreply.github.com> Date: Tue, 18 Nov 2025 21:25:29 +0900 Subject: [PATCH 1/2] feat: unify note display using virtual lines above target line Change M.refresh_buffer to use M.display_note_as_virtual_line instead of M.display_note, ensuring consistent display behavior between unnamed sessions and retrace mode. Notes now appear above the target line in both modes, improving visual consistency. This change: - Uses virt_lines_above for all note displays - Removes the eol (end-of-line) display mode - Shares the same rendering logic between sessions and retrace mode --- lua/tabi/ui/display.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/tabi/ui/display.lua b/lua/tabi/ui/display.lua index 6798a15..70a3776 100644 --- a/lua/tabi/ui/display.lua +++ b/lua/tabi/ui/display.lua @@ -113,7 +113,7 @@ function M.refresh_buffer(bufnr, notes) M.clear_buffer(bufnr) for _, note in ipairs(notes) do - M.display_note(bufnr, note) + M.display_note_as_virtual_line(bufnr, note) end end From 49af11916b3ef0cdebf8a3ec809d5b0ba89745b0 Mon Sep 17 00:00:00 2001 From: ushmz <44394399+ushmz@users.noreply.github.com> Date: Tue, 18 Nov 2025 21:25:45 +0900 Subject: [PATCH 2/2] test: update assertions for virtual lines display Update note_lifecycle_spec.lua to verify virt_lines instead of virt_text, aligning test expectations with the new unified display behavior. Tests now check for virt_lines_above implementation in both note creation and update scenarios. Changes: - Replace virt_text checks with virt_lines checks - Update extmark data access pattern (virt_lines[1][1][1]) - Maintain test coverage for display functionality --- lua/tabi/ui/display.lua | 30 --------- test/tabi/integration/note_lifecycle_spec.lua | 22 +++--- test/tabi/ui/display_spec.lua | 67 +------------------ 3 files changed, 13 insertions(+), 106 deletions(-) diff --git a/lua/tabi/ui/display.lua b/lua/tabi/ui/display.lua index 70a3776..0ceb55f 100644 --- a/lua/tabi/ui/display.lua +++ b/lua/tabi/ui/display.lua @@ -2,7 +2,6 @@ local M = {} local config = require("tabi.config") -local note_module = require("tabi.note") -- Namespace for virtual text and signs local ns = vim.api.nvim_create_namespace("tabi") @@ -30,35 +29,6 @@ function M.clear_buffer(bufnr) vim.fn.sign_unplace("tabi", { buffer = bufnr }) end ---- Display a note in the buffer ----@param bufnr number ----@param note NoteData -function M.display_note(bufnr, note) - if not vim.api.nvim_buf_is_valid(bufnr) then - return - end - - local cfg = config.get() - local line = note.line - 1 -- 0-indexed for API - - -- Add sign - if cfg.ui.use_icons then - vim.fn.sign_place(0, "tabi", SIGN_NAME, bufnr, { - lnum = note.line, - priority = 10, - }) - end - - -- Add virtual text with preview - local preview = note_module.get_preview(note, cfg.ui.note_preview_length) - if preview and preview ~= "" then - vim.api.nvim_buf_set_extmark(bufnr, ns, line, 0, { - virt_text = { { " " .. preview, "TabiNote" } }, - virt_text_pos = "eol", - }) - end -end - --- Display a note as virtual lines below the target line ---@param bufnr number ---@param note NoteData diff --git a/test/tabi/integration/note_lifecycle_spec.lua b/test/tabi/integration/note_lifecycle_spec.lua index 9c4a978..46f50fa 100644 --- a/test/tabi/integration/note_lifecycle_spec.lua +++ b/test/tabi/integration/note_lifecycle_spec.lua @@ -170,15 +170,15 @@ describe("integration: note lifecycle", function() assert.is_true(#signs[1].signs > 0) assert.are.equal(2, signs[1].signs[1].lnum) - -- Verify virtual text is added + -- Verify virtual lines are added local extmarks = vim.api.nvim_buf_get_extmarks(test_bufnr, ns, 0, -1, { details = true }) - local found_virt_text = false + local found_virt_lines = false for _, mark in ipairs(extmarks) do - if mark[4] and mark[4].virt_text then - found_virt_text = true + if mark[4] and mark[4].virt_lines then + found_virt_lines = true end end - assert.is_true(found_virt_text) + assert.is_true(found_virt_lines) -- 4. Verify persistence (session was saved by add_note) local loaded = session_module.load(session.id) @@ -207,12 +207,12 @@ describe("integration: note lifecycle", function() local notes_before = session_module.get_notes_for_file(session, test_file) display.refresh_buffer(test_bufnr, notes_before) - -- Verify initial virtual text + -- Verify initial virtual lines local extmarks_before = vim.api.nvim_buf_get_extmarks(test_bufnr, ns, 0, -1, { details = true }) local original_text = nil for _, mark in ipairs(extmarks_before) do - if mark[4] and mark[4].virt_text then - original_text = mark[4].virt_text[1][1] + if mark[4] and mark[4].virt_lines then + original_text = mark[4].virt_lines[1][1][1] end end assert.is_not_nil(original_text) @@ -225,12 +225,12 @@ describe("integration: note lifecycle", function() local notes_after = session_module.get_notes_for_file(session, test_file) display.refresh_buffer(test_bufnr, notes_after) - -- Verify updated virtual text + -- Verify updated virtual lines local extmarks_after = vim.api.nvim_buf_get_extmarks(test_bufnr, ns, 0, -1, { details = true }) local updated_text = nil for _, mark in ipairs(extmarks_after) do - if mark[4] and mark[4].virt_text then - updated_text = mark[4].virt_text[1][1] + if mark[4] and mark[4].virt_lines then + updated_text = mark[4].virt_lines[1][1][1] end end assert.is_not_nil(updated_text) diff --git a/test/tabi/ui/display_spec.lua b/test/tabi/ui/display_spec.lua index 15159eb..99f9f82 100644 --- a/test/tabi/ui/display_spec.lua +++ b/test/tabi/ui/display_spec.lua @@ -44,69 +44,6 @@ describe("tabi.ui.display", function() end) end) - describe("display_note", function() - before_each(function() - display.init() - end) - - it("should place sign at note line", function() - local note = note_module.create("/test.lua", 2, "Test note") - - display.display_note(bufnr, note) - - local signs = vim.fn.sign_getplaced(bufnr, { group = "tabi" }) - assert.are.equal(1, #signs) - assert.is_true(#signs[1].signs > 0) - assert.are.equal(2, signs[1].signs[1].lnum) - end) - - it("should add virtual text with preview", function() - local note = note_module.create("/test.lua", 3, "This is a test note") - - display.display_note(bufnr, note) - - -- Get extmarks - local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, { details = true }) - assert.is_true(#extmarks > 0) - - -- Check virtual text exists - local found_virt_text = false - for _, mark in ipairs(extmarks) do - if mark[4] and mark[4].virt_text then - found_virt_text = true - -- Check that virtual text contains note preview - local virt_text = mark[4].virt_text[1][1] - assert.is_true(virt_text:find("This is a test note") ~= nil) - end - end - assert.is_true(found_virt_text) - end) - - it("should respect preview length from config", function() - config.setup({ ui = { note_preview_length = 10 } }) - local note = note_module.create("/test.lua", 1, "This is a very long note content") - - display.display_note(bufnr, note) - - local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, { details = true }) - for _, mark in ipairs(extmarks) do - if mark[4] and mark[4].virt_text then - local virt_text = mark[4].virt_text[1][1] - -- Should be truncated (10 chars + "...") - assert.is_true(#virt_text <= 20) -- space + 10 chars + "..." - end - end - end) - - it("should not display for invalid buffer", function() - local invalid_bufnr = 99999 - local note = note_module.create("/test.lua", 1, "Test") - - -- Should not throw error - display.display_note(invalid_bufnr, note) - end) - end) - describe("display_note_as_virtual_line", function() before_each(function() display.init() @@ -160,7 +97,7 @@ describe("tabi.ui.display", function() it("should remove all extmarks", function() local note = note_module.create("/test.lua", 1, "Test") - display.display_note(bufnr, note) + display.display_note_as_virtual_line(bufnr, note) -- Verify extmarks exist local before = vim.api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, {}) @@ -174,7 +111,7 @@ describe("tabi.ui.display", function() it("should remove all signs", function() local note = note_module.create("/test.lua", 2, "Test") - display.display_note(bufnr, note) + display.display_note_as_virtual_line(bufnr, note) display.clear_buffer(bufnr)