Skip to content

Comments

fix(parser): exclude git diff metadata from neogit filename patterns#127

Merged
barrettruth merged 1 commit intomainfrom
fix/highlight-file
Feb 16, 2026
Merged

fix(parser): exclude git diff metadata from neogit filename patterns#127
barrettruth merged 1 commit intomainfrom
fix/highlight-file

Conversation

@barrettruth
Copy link
Owner

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.

Problem: "new file mode 100644" and "deleted file mode 100644" lines in
git diff output matched the neogit "new file" and "deleted" filename
patterns, corrupting the current filename and breaking syntax
highlighting for subsequent hunks.

Solution: add negative guards so "new file mode" and "deleted file mode"
lines are skipped before the neogit capture runs. Guard order matters
for Lua and/not semantics — the negative check must evaluate first to
avoid the and-operator returning true instead of the captured string.
@barrettruth
Copy link
Owner Author

@phanen here's the fix. the logic is low key a bit scuffed and may need to get organized in the future. but i tested it with your examples and it fixed it. let me know - i marked this pr as closing the issue.

I keep adding new tests but damn, you keep finding things :/ (well, it is good - just wish I thought of these things ahead of time).

Thanks again!

@barrettruth
Copy link
Owner Author

image

@barrettruth barrettruth merged commit d68cddb into main Feb 16, 2026
7 checks passed
@barrettruth barrettruth deleted the fix/highlight-file branch February 16, 2026 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

filetype highlight sometime don't work at first time

1 participant