fix(parser): exclude git diff metadata from neogit filename patterns (#127)
## Problem Git diff metadata lines like "new file mode 100644" and "deleted file mode 100644" matched the neogit "new file" and "deleted" filename patterns in the parser, corrupting the current filename and breaking syntax highlighting for subsequent hunks. Closes #120 ## Solution Add negative guards so "new file mode" and "deleted file mode" lines are skipped before the neogit filename capture runs. The guard must evaluate before the capture due to Lua's and/or short-circuit semantics — otherwise the and-operator returns true instead of the captured string. Added 16 parser tests covering all neogit filename patterns, all git diff extended header lines that could collide, and integration scenarios with mixed neogit status + diff metadata buffers.
This commit is contained in:
parent
cbc93f9eaa
commit
d68cddb1a4
2 changed files with 306 additions and 2 deletions
|
|
@ -197,8 +197,8 @@ function M.parse_buffer(bufnr)
|
|||
for i, line in ipairs(lines) do
|
||||
local diff_git_file = line:match('^diff %-%-git a/.+ b/(.+)$')
|
||||
local neogit_file = line:match('^modified%s+(.+)$')
|
||||
or line:match('^new file%s+(.+)$')
|
||||
or line:match('^deleted%s+(.+)$')
|
||||
or (not line:match('^new file mode') and line:match('^new file%s+(.+)$'))
|
||||
or (not line:match('^deleted file mode') and line:match('^deleted%s+(.+)$'))
|
||||
or line:match('^renamed%s+(.+)$')
|
||||
or line:match('^copied%s+(.+)$')
|
||||
local bare_file = not hunk_start and line:match('^([^%s]+%.[^%s]+)$')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue