fix(parser): emit hunks for files with unknown filetypes

Previously, hunks were discarded entirely if vim.filetype.match()
returned nil. This meant files with unrecognized extensions got no
highlighting at all - not even the basic green/red backgrounds for
added/deleted lines.

Remove the (current_lang or current_ft) condition from flush_hunk()
so all hunks are collected. highlight_hunk() already handles the
case where ft/lang are nil by skipping syntax highlighting but still
applying background colors.

Co-authored-by: phanen <phanen@qq.com>
This commit is contained in:
Barrett Ruth 2026-02-04 23:51:15 -05:00
parent 83f6069d49
commit 980bedc8a6
2 changed files with 20 additions and 1 deletions

View file

@ -285,5 +285,24 @@ describe('parser', function()
assert.are.equal('diff --git a/parser.lua b/parser.lua', hunks[1].header_lines[1])
delete_buffer(bufnr)
end)
it('emits hunk for files with unknown filetype', function()
local bufnr = create_buffer({
'M config.obscuretype',
'@@ -1,2 +1,3 @@',
' setting1 = value1',
'-setting2 = value2',
'+setting2 = MODIFIED',
'+setting4 = newvalue',
})
local hunks = parser.parse_buffer(bufnr)
assert.are.equal(1, #hunks)
assert.are.equal('config.obscuretype', hunks[1].filename)
assert.is_nil(hunks[1].ft)
assert.is_nil(hunks[1].lang)
assert.are.equal(4, #hunks[1].lines)
delete_buffer(bufnr)
end)
end)
end)