Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions lua/tabi/ui/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -113,7 +83,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

Expand Down
22 changes: 11 additions & 11 deletions test/tabi/integration/note_lifecycle_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
67 changes: 2 additions & 65 deletions test/tabi/ui/display_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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, {})
Expand All @@ -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)

Expand Down