fix(hunks): remove hunk overlay
This commit is contained in:
@@ -47,14 +47,6 @@ local function sign_marks(buf)
|
||||
return out
|
||||
end
|
||||
|
||||
---@param buf integer
|
||||
---@param ns_name string
|
||||
---@return vim.api.keyset.get_extmark_item[]
|
||||
local function detailed_marks(buf, ns_name)
|
||||
local ns = vim.api.nvim_get_namespaces()[ns_name]
|
||||
return vim.api.nvim_buf_get_extmarks(buf, ns, 0, -1, { details = true })
|
||||
end
|
||||
|
||||
---@return integer?
|
||||
local function find_float()
|
||||
for _, w in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
@@ -64,19 +56,6 @@ local function find_float()
|
||||
end
|
||||
end
|
||||
|
||||
---@param hl string|string[]?
|
||||
---@param group string
|
||||
---@return boolean
|
||||
local function has_hl(hl, group)
|
||||
if hl == group then
|
||||
return true
|
||||
end
|
||||
if type(hl) == "table" then
|
||||
return vim.tbl_contains(hl, group)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
t.test("pure add: hunk shape and add signs", function()
|
||||
local _, buf, state = setup("a\nd\n", "a\nb\nc\nd\n")
|
||||
t.eq(#state.hunks, 1, "one hunk for a pure addition")
|
||||
@@ -160,134 +139,6 @@ t.test("editing the buffer refreshes signs", function()
|
||||
t.eq(hk.type, "change")
|
||||
end)
|
||||
|
||||
t.test("overlay: change hunk shows deletion and addition", function()
|
||||
local _, buf = setup("a\nb\nc\n", "a\nB\nc\n")
|
||||
hunks.toggle_overlay(buf)
|
||||
---@type integer?
|
||||
local add_row
|
||||
---@type vim.api.keyset.extmark_details?
|
||||
local add_d
|
||||
---@type vim.api.keyset.extmark_details?
|
||||
local virt_d
|
||||
for _, m in ipairs(detailed_marks(buf, "ow.git.hunks.overlay")) do
|
||||
local d = assert(m[4])
|
||||
if d.line_hl_group then
|
||||
add_row, add_d = m[2], d
|
||||
elseif d.virt_lines then
|
||||
virt_d = d
|
||||
end
|
||||
end
|
||||
add_d = assert(add_d, "the added line should get a line highlight")
|
||||
t.eq(add_row, 1, "addition highlighted on the changed line")
|
||||
t.eq(add_d.line_hl_group, "GitHunkAddLine")
|
||||
virt_d = assert(virt_d, "the deletion should render as virtual lines")
|
||||
local piece = assert(assert(assert(virt_d.virt_lines)[1])[1])
|
||||
t.truthy(
|
||||
vim.startswith(piece[1], "b"),
|
||||
"deleted line shows the old content"
|
||||
)
|
||||
t.truthy(has_hl(piece[2], "GitHunkDeleteLine"))
|
||||
t.truthy(has_hl(piece[2], "DiffText"))
|
||||
local seen_inline = false
|
||||
for _, m in ipairs(detailed_marks(buf, "ow.git.hunks.overlay")) do
|
||||
local d = assert(m[4])
|
||||
if d.hl_group == "DiffText" then
|
||||
seen_inline = true
|
||||
t.eq(m[2], 1, "inline addition highlight is on the changed line")
|
||||
t.eq(m[3], 0, "inline addition starts at the changed byte")
|
||||
t.eq(d.end_col, 1, "inline addition ends after the changed byte")
|
||||
end
|
||||
end
|
||||
t.truthy(seen_inline, "the added side gets an inline highlight")
|
||||
end)
|
||||
|
||||
t.test("overlay: delete hunk shows only deletion lines", function()
|
||||
local _, buf = setup("a\nb\nc\n", "a\nc\n")
|
||||
hunks.toggle_overlay(buf)
|
||||
local marks = detailed_marks(buf, "ow.git.hunks.overlay")
|
||||
t.eq(#marks, 1, "a pure delete has no addition highlight")
|
||||
local d = assert(assert(marks[1])[4])
|
||||
local piece = assert(assert(assert(d.virt_lines)[1])[1])
|
||||
t.truthy(vim.startswith(piece[1], "b"))
|
||||
t.eq(piece[2], "GitHunkDeleteLine")
|
||||
end)
|
||||
|
||||
t.test("overlay: add hunk highlights the added lines", function()
|
||||
local _, buf = setup("a\nd\n", "a\nb\nc\nd\n")
|
||||
hunks.toggle_overlay(buf)
|
||||
local rows = {}
|
||||
for _, m in ipairs(detailed_marks(buf, "ow.git.hunks.overlay")) do
|
||||
local d = assert(m[4])
|
||||
t.falsy(d.virt_lines, "a pure add has no deletion virtual lines")
|
||||
t.eq(d.line_hl_group, "GitHunkAddLine")
|
||||
table.insert(rows, m[2])
|
||||
end
|
||||
table.sort(rows)
|
||||
t.eq(rows, { 1, 2 }, "both added lines highlighted")
|
||||
end)
|
||||
|
||||
t.test("overlay: deleted lines are treesitter-highlighted", function()
|
||||
local _, buf =
|
||||
setup("-- a note\nlocal x = 1\nlocal y = 2\n", "local y = 2\n", "a.lua")
|
||||
t.truthy(
|
||||
pcall(vim.treesitter.start, buf, "lua"),
|
||||
"the lua parser should be available"
|
||||
)
|
||||
hunks.toggle_overlay(buf)
|
||||
---@type table[]?
|
||||
local virt
|
||||
for _, m in ipairs(detailed_marks(buf, "ow.git.hunks.overlay")) do
|
||||
local d = assert(m[4])
|
||||
if d.virt_lines then
|
||||
virt = d.virt_lines
|
||||
end
|
||||
end
|
||||
virt = assert(virt, "a deletion virtual line should render")
|
||||
---@type table<string, boolean>
|
||||
local seen = {}
|
||||
for _, line in ipairs(virt) do
|
||||
for _, c in ipairs(line) do
|
||||
local hl = c[2]
|
||||
if
|
||||
type(hl) == "table"
|
||||
and hl[1] == "GitHunkDeleteLine"
|
||||
and hl[2]
|
||||
then
|
||||
seen[hl[2]] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
t.truthy(seen["@comment"], "the deleted comment keeps its @comment group")
|
||||
t.truthy(seen["@keyword"], "deleted code keeps its syntax groups")
|
||||
end)
|
||||
|
||||
t.test("overlay: toggling swaps gutter signs for the overlay", function()
|
||||
local _, buf = setup("a\nb\nc\n", "a\nB\nc\n")
|
||||
t.truthy(
|
||||
#detailed_marks(buf, "ow.git.hunks") > 0,
|
||||
"gutter signs present while the overlay is off"
|
||||
)
|
||||
t.eq(#detailed_marks(buf, "ow.git.hunks.overlay"), 0)
|
||||
|
||||
hunks.toggle_overlay(buf)
|
||||
t.truthy(
|
||||
#detailed_marks(buf, "ow.git.hunks.overlay") > 0,
|
||||
"overlay present once it is on"
|
||||
)
|
||||
t.eq(
|
||||
#detailed_marks(buf, "ow.git.hunks"),
|
||||
0,
|
||||
"gutter signs replaced while the overlay is on"
|
||||
)
|
||||
|
||||
hunks.toggle_overlay(buf)
|
||||
t.eq(#detailed_marks(buf, "ow.git.hunks.overlay"), 0)
|
||||
t.truthy(
|
||||
#detailed_marks(buf, "ow.git.hunks") > 0,
|
||||
"gutter signs restored after toggling the overlay off"
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("toggle_stage stages the change into the index", function()
|
||||
local dir, buf = setup("a\nb\nc\n", "a\nB\nc\n")
|
||||
vim.api.nvim_win_set_cursor(0, { 2, 0 })
|
||||
|
||||
Reference in New Issue
Block a user