refactor(git): remove blame gutter
This commit is contained in:
@@ -197,7 +197,6 @@ t.test("blame actions are no-ops off a worktree", function()
|
||||
t.quietly(function()
|
||||
blame.line_popup(buf)
|
||||
blame.toggle_inline(buf)
|
||||
blame.toggle_gutter(buf)
|
||||
end)
|
||||
t.eq(blame.state(buf), nil, "no state created for a non-worktree buffer")
|
||||
end)
|
||||
@@ -301,204 +300,6 @@ t.test("inline annotation follows the cursor", function()
|
||||
t.eq(assert(inline_marks(buf)[1])[2], 2, "annotation moved to line 3")
|
||||
end)
|
||||
|
||||
t.test("gutter toggle sets and clears the statuscolumn", function()
|
||||
local _, buf = setup("a\nb\nc\nd\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
blame.toggle_gutter(buf)
|
||||
t.truthy(
|
||||
vim.wo[win].statuscolumn ~= "",
|
||||
"the gutter sets the window statuscolumn"
|
||||
)
|
||||
blame.toggle_gutter(buf)
|
||||
t.eq(vim.wo[win].statuscolumn, "", "toggling off clears it")
|
||||
end)
|
||||
|
||||
t.test("gutter saves and restores the statuscolumn", function()
|
||||
local _, buf = setup("a\nb\nc\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
t.defer(function()
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
vim.wo[win].statuscolumn = ""
|
||||
vim.wo[win].signcolumn = "auto"
|
||||
end
|
||||
end)
|
||||
vim.wo[win].statuscolumn = "%l custom"
|
||||
vim.wo[win].signcolumn = "yes:2"
|
||||
blame.toggle_gutter(buf)
|
||||
t.truthy(
|
||||
vim.wo[win].statuscolumn ~= "%l custom",
|
||||
"the gutter overrides a custom statuscolumn"
|
||||
)
|
||||
t.eq(
|
||||
vim.wo[win].signcolumn,
|
||||
"yes:2",
|
||||
"the gutter leaves signcolumn untouched"
|
||||
)
|
||||
blame.toggle_gutter(buf)
|
||||
t.eq(vim.wo[win].statuscolumn, "%l custom", "statuscolumn restored")
|
||||
end)
|
||||
|
||||
t.test("gutter uses the full preferred width when it can", function()
|
||||
local _, buf = setup("a\nb\nc\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
t.defer(function()
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
vim.wo[win].statuscolumn = ""
|
||||
end
|
||||
end)
|
||||
vim.wo[win].number = false
|
||||
vim.wo[win].relativenumber = false
|
||||
vim.wo[win].signcolumn = "no"
|
||||
vim.wo[win].foldcolumn = "0"
|
||||
blame.toggle_gutter(buf)
|
||||
t.wait_for(function()
|
||||
local s = blame.state(buf)
|
||||
return s ~= nil and s.blame_width ~= nil
|
||||
end, "the gutter blame to render")
|
||||
t.eq(
|
||||
assert(blame.state(buf)).blame_width,
|
||||
40,
|
||||
"with no native columns the blame takes its full preferred width"
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("gutter is budgeted under the 47-cell cap", function()
|
||||
local _, buf = setup("a\nb\nc\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
t.defer(function()
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
vim.wo[win].statuscolumn = ""
|
||||
vim.wo[win].signcolumn = "auto"
|
||||
end
|
||||
end)
|
||||
vim.wo[win].number = false
|
||||
vim.wo[win].relativenumber = false
|
||||
vim.wo[win].foldcolumn = "0"
|
||||
vim.wo[win].signcolumn = "yes:9"
|
||||
blame.toggle_gutter(buf)
|
||||
t.wait_for(function()
|
||||
local s = blame.state(buf)
|
||||
return s ~= nil and s.blame_width ~= nil
|
||||
end, "the gutter blame to render")
|
||||
local width = assert(assert(blame.state(buf)).blame_width)
|
||||
local native = 18 -- signcolumn=yes:9 reserves 2*9 cells
|
||||
t.eq(width, 47 - native, "the blame is budgeted into the cells left free")
|
||||
t.truthy(width + native <= 47, "blame plus native columns fits the cap")
|
||||
end)
|
||||
|
||||
t.test("gutter re-budgets when a gutter option changes", function()
|
||||
local _, buf = setup("a\nb\nc\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
t.defer(function()
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
vim.wo[win].statuscolumn = ""
|
||||
vim.wo[win].signcolumn = "auto"
|
||||
end
|
||||
end)
|
||||
vim.wo[win].number = false
|
||||
vim.wo[win].relativenumber = false
|
||||
vim.wo[win].foldcolumn = "0"
|
||||
vim.wo[win].signcolumn = "no"
|
||||
blame.toggle_gutter(buf)
|
||||
t.wait_for(function()
|
||||
local s = blame.state(buf)
|
||||
return s ~= nil and s.blame_width ~= nil
|
||||
end, "the gutter blame to render")
|
||||
t.eq(
|
||||
assert(blame.state(buf)).blame_width,
|
||||
40,
|
||||
"a clear gutter leaves the full preferred width"
|
||||
)
|
||||
|
||||
vim.wo[win].signcolumn = "yes:9"
|
||||
t.wait_for(function()
|
||||
return assert(blame.state(buf)).blame_width == 47 - 18
|
||||
end, "the blame to re-budget for the widened signcolumn")
|
||||
end)
|
||||
|
||||
t.test("the gutter statuscolumn does not leak into other windows", function()
|
||||
local _, buf = setup("a\nb\nc\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
blame.toggle_gutter(buf)
|
||||
t.wait_for(function()
|
||||
local s = blame.state(buf)
|
||||
return s ~= nil and s.blame_width ~= nil
|
||||
end, "the gutter to render")
|
||||
t.falsy(
|
||||
vim.go.statuscolumn:find("git.blame", 1, true),
|
||||
"the gutter leaves the global statuscolumn untouched"
|
||||
)
|
||||
|
||||
vim.cmd("new")
|
||||
local plain = vim.api.nvim_get_current_win()
|
||||
t.defer(function()
|
||||
if vim.api.nvim_win_is_valid(plain) then
|
||||
vim.api.nvim_win_close(plain, true)
|
||||
end
|
||||
end)
|
||||
t.falsy(
|
||||
vim.wo[plain].statuscolumn:find("git.blame", 1, true),
|
||||
"a new window does not inherit the blame gutter"
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("gutter shows sha, author and an absolute date", function()
|
||||
local _, buf = setup("a\nb\nc\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
blame.toggle_gutter(buf)
|
||||
t.wait_for(function()
|
||||
local s = blame.state(buf)
|
||||
return s ~= nil and s.tick ~= nil
|
||||
end, "the gutter blame to populate")
|
||||
local state = assert(blame.state(buf))
|
||||
local g = assert(state.blame_text)[1] or ""
|
||||
t.truthy(g:match("%x%x%x%x%x%x%x%x"), "the gutter shows a short sha")
|
||||
t.truthy(g:find("t", 1, true), "the gutter shows the author")
|
||||
t.truthy(
|
||||
g:match("%d%d%d%d%-%d%d%-%d%d"),
|
||||
"the gutter shows a YYYY-MM-DD date"
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("gutter is blank on virtual lines", function()
|
||||
local _, buf = setup("a\nb\nc\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
blame.toggle_gutter(buf)
|
||||
t.wait_for(function()
|
||||
local s = blame.state(buf)
|
||||
return s ~= nil and s.tick ~= nil
|
||||
end, "the gutter blame to populate")
|
||||
local state = assert(blame.state(buf))
|
||||
local blank = assert(state.blame_blank)
|
||||
t.falsy(blank:match("%x%x%x%x%x%x%x%x"), "no sha on a virtual line")
|
||||
t.falsy(blank:match("%S"), "blank segment is whitespace")
|
||||
end)
|
||||
|
||||
t.test("the statuscolumn expression renders the blame gutter", function()
|
||||
local dir, buf = setup("a\nb\nc\n")
|
||||
local sha = h.git(dir, "rev-parse", "HEAD").stdout
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
blame.toggle_gutter(buf)
|
||||
t.wait_for(function()
|
||||
local s = blame.state(buf)
|
||||
return s ~= nil and s.tick ~= nil
|
||||
end, "the gutter blame to populate")
|
||||
local rendered = vim.api.nvim_eval_statusline(
|
||||
"%{%v:lua.require('git.blame').statuscolumn()%}",
|
||||
{ winid = win, use_statuscol_lnum = 1 }
|
||||
)
|
||||
t.truthy(
|
||||
rendered.str:find(sha:sub(1, 8), 1, true),
|
||||
"the statuscolumn renders the commit's short sha"
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("open_commit opens the commit that last touched the line", function()
|
||||
local _, buf = setup("alpha\nbeta\ngamma\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
@@ -559,12 +360,8 @@ end)
|
||||
t.test("detach clears blame state and annotations", function()
|
||||
local _, buf = setup("a\nb\nc\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
enable_blame(buf)
|
||||
blame.toggle_gutter(buf)
|
||||
t.truthy(vim.wo[win].statuscolumn ~= "", "the gutter statuscolumn set")
|
||||
blame.detach(buf)
|
||||
t.eq(blame.state(buf), nil, "state dropped on detach")
|
||||
t.eq(#inline_marks(buf), 0, "inline annotation cleared")
|
||||
t.eq(vim.wo[win].statuscolumn, "", "gutter statuscolumn cleared")
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user