feat(parser): support combined diff format

Problem: `parse_buffer` didn't recognize `diff --combined` /
`diff --cc` headers, couldn't parse `@@@` old-side ranges, and
synthesized empty body lines as single-space regardless of prefix
width.

Solution: Add `diff --combined` and `diff --cc` filename patterns,
parse old-side `-start,count` from `@@@` lines, remove
`is_unified_diff` guard on empty body lines, and use
`string.rep(' ', hunk_prefix_width)` for synthetic context lines.
This commit is contained in:
Barrett Ruth 2026-03-05 01:06:37 -05:00
parent 38e0187998
commit bb87ae279b
2 changed files with 14 additions and 5 deletions

View file

@ -234,6 +234,8 @@ function M.parse_buffer(bufnr)
end
local diff_git_file = logical:match('^diff %-%-git a/.+ b/(.+)$')
or logical:match('^diff %-%-combined (.+)$')
or logical:match('^diff %-%-cc (.+)$')
local neogit_file = logical:match('^modified%s+(.+)$')
or (not logical:match('^new file mode') and logical:match('^new file%s+(.+)$'))
or (not logical:match('^deleted file mode') and logical:match('^deleted%s+(.+)$'))
@ -286,10 +288,17 @@ function M.parse_buffer(bufnr)
new_remaining = file_new_count
end
else
local hs, hc = logical:match('%-(%d+),?(%d*)')
if hs then
file_old_start = tonumber(hs)
file_old_count = tonumber(hc) or 1
old_remaining = file_old_count
end
local hs2, hc2 = logical:match('%+(%d+),?(%d*) @@')
if hs2 then
file_new_start = tonumber(hs2)
file_new_count = tonumber(hc2) or 1
new_remaining = file_new_count
end
end
local at_end, context = logical:match('^(@@+.-@@+%s*)(.*)')
@ -312,13 +321,12 @@ function M.parse_buffer(bufnr)
end
elseif
logical == ''
and is_unified_diff
and old_remaining
and old_remaining > 0
and new_remaining
and new_remaining > 0
then
table.insert(hunk_lines, ' ')
table.insert(hunk_lines, string.rep(' ', hunk_prefix_width))
old_remaining = old_remaining - 1
new_remaining = new_remaining - 1
elseif