From 980bedc8a6e2180d60462204d54bbc1d4dd7c613 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Wed, 4 Feb 2026 23:51:15 -0500 Subject: [PATCH] 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 --- lua/diffs/parser.lua | 2 +- spec/parser_spec.lua | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lua/diffs/parser.lua b/lua/diffs/parser.lua index bbb8ab5..da3b291 100644 --- a/lua/diffs/parser.lua +++ b/lua/diffs/parser.lua @@ -68,7 +68,7 @@ function M.parse_buffer(bufnr) local header_lines = {} local function flush_hunk() - if hunk_start and #hunk_lines > 0 and (current_lang or current_ft) then + if hunk_start and #hunk_lines > 0 then local hunk = { filename = current_filename, ft = current_ft, diff --git a/spec/parser_spec.lua b/spec/parser_spec.lua index 9d2c01b..5323d09 100644 --- a/spec/parser_spec.lua +++ b/spec/parser_spec.lua @@ -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)