Skip to content

fix(highlight): avoid leaking diff syntax into active buffers - #300

Merged
dlyongemallo merged 1 commit into
dlyongemallo:mainfrom
carlos-algms:fix/prevent-diff-syntax-leak
Aug 15, 2026
Merged

fix(highlight): avoid leaking diff syntax into active buffers#300
dlyongemallo merged 1 commit into
dlyongemallo:mainfrom
carlos-algms:fix/prevent-diff-syntax-leak

Conversation

@carlos-algms

@carlos-algms carlos-algms commented Aug 9, 2026

Copy link
Copy Markdown

When Diffview initializes and diffAdded is undefined, it sources Neovim's syntax/diff.vim in the current buffer.

In Tree-sitter-only setups, b:current_syntax can 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.

  • Replace syntax-file sourcing with default highlight links
  • Preserve user-defined diff highlight groups
  • Add regression coverage for buffer contamination

@carlos-algms
carlos-algms marked this pull request as ready for review August 9, 2026 07:08
@dlyongemallo
dlyongemallo requested a lite review from Copilot August 14, 2026 13:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and diffChanged.
  • 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.

Comment thread lua/diffview/tests/functional/highlight_spec.lua
Comment thread lua/diffview/tests/functional/highlight_spec.lua
@dlyongemallo
dlyongemallo merged commit f1d46fa into dlyongemallo:main Aug 15, 2026
7 of 8 checks passed
@dlyongemallo

Copy link
Copy Markdown
Owner

Thanks @carlos-algms for the fix!

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.

3 participants