feat: update

This commit is contained in:
Barrett Ruth 2026-02-02 15:34:37 -05:00
parent 2c330732bb
commit a082b9c4b3
2 changed files with 160 additions and 4 deletions

View file

@ -78,12 +78,17 @@ CONFIGURATION *fugitive-ts-config*
*fugitive-ts.VimConfig* *fugitive-ts.VimConfig*
Vim config fields: ~ Vim config fields: ~
{enabled} (boolean, default: false) {enabled} (boolean, default: false)
Experimental: Use vim syntax highlighting as Use vim syntax highlighting as fallback when no
fallback when no treesitter parser is available. treesitter parser is available for a language.
Creates a scratch buffer, sets the filetype, and
queries |synID()| per character to extract
highlight groups. Slower than treesitter but
covers languages without a TS parser installed.
{max_lines} (integer, default: 200) {max_lines} (integer, default: 200)
Skip vim syntax highlighting for hunks larger than Skip vim syntax highlighting for hunks larger than
this many lines. this many lines. Lower than the treesitter default
due to the per-character cost of |synID()|.
*fugitive-ts.Highlights* *fugitive-ts.Highlights*
Highlights table fields: ~ Highlights table fields: ~

View file

@ -131,7 +131,7 @@ describe('highlight', function()
delete_buffer(bufnr) delete_buffer(bufnr)
end) end)
it('does nothing for nil lang', function() it('does nothing for nil lang and nil ft', function()
local bufnr = create_buffer({ local bufnr = create_buffer({
'@@ -1,1 +1,2 @@', '@@ -1,1 +1,2 @@',
' some content', ' some content',
@ -140,6 +140,7 @@ describe('highlight', function()
local hunk = { local hunk = {
filename = 'test.unknown', filename = 'test.unknown',
ft = nil,
lang = nil, lang = nil,
start_line = 1, start_line = 1,
lines = { ' some content', '+more content' }, lines = { ' some content', '+more content' },
@ -530,5 +531,155 @@ describe('highlight', function()
assert.is_true(has_diff_add) assert.is_true(has_diff_add)
delete_buffer(bufnr) delete_buffer(bufnr)
end) end)
it('applies vim syntax extmarks when vim.enabled and no TS parser', function()
local bufnr = create_buffer({
'@@ -1,1 +1,2 @@',
' local x = 1',
'+local y = 2',
})
local hunk = {
filename = 'test.lua',
ft = 'lua',
lang = nil,
start_line = 1,
lines = { ' local x = 1', '+local y = 2' },
}
highlight.highlight_hunk(bufnr, ns, hunk, default_opts({ vim = { enabled = true } }))
local extmarks = get_extmarks(bufnr)
local has_syntax_hl = false
for _, mark in ipairs(extmarks) do
if mark[4] and mark[4].hl_group and mark[4].hl_group ~= 'Normal' then
has_syntax_hl = true
break
end
end
assert.is_true(has_syntax_hl)
delete_buffer(bufnr)
end)
it('skips vim fallback when vim.enabled is false', function()
local bufnr = create_buffer({
'@@ -1,1 +1,2 @@',
' local x = 1',
'+local y = 2',
})
local hunk = {
filename = 'test.lua',
ft = 'lua',
lang = nil,
start_line = 1,
lines = { ' local x = 1', '+local y = 2' },
}
highlight.highlight_hunk(bufnr, ns, hunk, default_opts({ vim = { enabled = false } }))
local extmarks = get_extmarks(bufnr)
local has_syntax_hl = false
for _, mark in ipairs(extmarks) do
if mark[4] and mark[4].hl_group and mark[4].hl_group ~= 'Normal' then
has_syntax_hl = true
break
end
end
assert.is_false(has_syntax_hl)
delete_buffer(bufnr)
end)
it('respects vim.max_lines', function()
local lines = { '@@ -1,100 +1,101 @@' }
local hunk_lines = {}
for i = 1, 250 do
table.insert(lines, ' line ' .. i)
table.insert(hunk_lines, ' line ' .. i)
end
local bufnr = create_buffer(lines)
local hunk = {
filename = 'test.lua',
ft = 'lua',
lang = nil,
start_line = 1,
lines = hunk_lines,
}
highlight.highlight_hunk(
bufnr,
ns,
hunk,
default_opts({ vim = { enabled = true, max_lines = 200 } })
)
local extmarks = get_extmarks(bufnr)
assert.are.equal(0, #extmarks)
delete_buffer(bufnr)
end)
it('applies background for vim fallback hunks', function()
local bufnr = create_buffer({
'@@ -1,1 +1,2 @@',
' local x = 1',
'+local y = 2',
})
local hunk = {
filename = 'test.lua',
ft = 'lua',
lang = nil,
start_line = 1,
lines = { ' local x = 1', '+local y = 2' },
}
highlight.highlight_hunk(
bufnr,
ns,
hunk,
default_opts({ vim = { enabled = true }, highlights = { background = true } })
)
local extmarks = get_extmarks(bufnr)
local has_diff_add = false
for _, mark in ipairs(extmarks) do
if mark[4] and mark[4].line_hl_group == 'FugitiveTsAdd' then
has_diff_add = true
break
end
end
assert.is_true(has_diff_add)
delete_buffer(bufnr)
end)
it('applies Normal blanking for vim fallback hunks', function()
local bufnr = create_buffer({
'@@ -1,1 +1,2 @@',
' local x = 1',
'+local y = 2',
})
local hunk = {
filename = 'test.lua',
ft = 'lua',
lang = nil,
start_line = 1,
lines = { ' local x = 1', '+local y = 2' },
}
highlight.highlight_hunk(bufnr, ns, hunk, default_opts({ vim = { enabled = true } }))
local extmarks = get_extmarks(bufnr)
local has_normal = false
for _, mark in ipairs(extmarks) do
if mark[4] and mark[4].hl_group == 'Normal' then
has_normal = true
break
end
end
assert.is_true(has_normal)
delete_buffer(bufnr)
end)
end) end)
end) end)