fix(highlight): avoid leaking diff syntax into active buffers - #300
Merged
dlyongemallo merged 1 commit intoAug 15, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents Diffview’s highlight initialization from contaminating non-diff buffers by avoiding runtime! syntax/diff.vim (which can install buffer-local ^+ / ^- syntax matches when b:current_syntax is unset). Instead, it provides safe default highlight links for diffAdded/diffRemoved/diffChanged, while keeping existing user-defined groups intact.
Changes:
- Replace diff-syntax sourcing with default highlight links for
diffAdded,diffRemoved, anddiffChanged. - Keep user-defined diff highlight groups unchanged via
default = true. - Add functional regression tests to ensure buffers aren’t polluted by diff syntax setup.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lua/diffview/hl.lua | Replaces syntax/diff.vim loading with safe default highlight links for diff groups. |
| lua/diffview/tests/functional/highlight_spec.lua | Adds regression coverage for buffer contamination and preservation of existing diff highlight groups. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Owner
|
Thanks @carlos-algms for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When Diffview initializes and
diffAddedis undefined, it sources Neovim'ssyntax/diff.vimin the current buffer.In Tree-sitter-only setups,
b:current_syntaxcan be unset, so this installs buffer-local^+and^-syntax matches.Unchanged files may then display addition and deletion colors based only on their line prefixes.