feat(highlight): warn when hunks exceed max_lines

Problem: when a hunk's highlighted lines exceed `max_lines`, syntax
highlighting is silently skipped. Users have no indication why parts
of their diff lack highlighting.

Solution: add `highlights.warn_max_lines` (default `true`) that emits
a `vim.notify` warning with the hunk index and line count vs threshold.
Also change `max_lines` to count only highlighted (`+`/`-`) lines
rather than total body lines including context.
This commit is contained in:
Barrett Ruth 2026-03-10 16:36:50 -04:00
parent c7cd8fc24c
commit 5199e72bd0
4 changed files with 74 additions and 22 deletions

View file

@ -93,6 +93,7 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
background = true,
gutter = true,
blend_alpha = 0.6,
warn_max_lines = true,
context = {
enabled = true,
lines = 25,
@ -249,6 +250,14 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
(inclusive). Higher values produce more vivid
backgrounds.
{warn_max_lines} (boolean, default: true)
Show a |vim.notify()| warning when a hunk's
highlighted lines (`+`/`-`) exceed {max_lines}
and syntax highlighting is skipped. The warning
includes the 1-indexed hunk number and the
line count vs. threshold so the user knows
which hunk was affected and what to adjust.
{context} (table, default: see below)
Syntax parsing context options.
See |diffs.ContextConfig| for fields.
@ -322,8 +331,10 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
Apply treesitter syntax highlighting to code.
{max_lines} (integer, default: 500)
Skip treesitter highlighting for hunks larger than
this many lines. Prevents lag on massive diffs.
Skip treesitter highlighting for hunks with more
highlighted lines (`+`/`-`) than this threshold.
Context lines are not counted. Prevents lag on
massive diffs.
*diffs.VimConfig*
Vim config fields: ~
@ -338,9 +349,11 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
parser installed (e.g., COBOL, Fortran).
{max_lines} (integer, default: 200)
Skip vim syntax highlighting for hunks larger than
this many lines. Lower than the treesitter default
due to the per-character cost of |synID()|.
Skip vim syntax highlighting for hunks with more
highlighted lines (`+`/`-`) than this threshold.
Context lines are not counted. Lower than the
treesitter default due to the per-character cost
of |synID()|.
*diffs.IntraConfig*
Intra config fields: ~
@ -359,8 +372,9 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
(falls back to default if not available).
{max_lines} (integer, default: 500)
Skip character-level highlighting for hunks larger
than this many lines.
Skip character-level highlighting for hunks with
more highlighted lines (`+`/`-`) than this
threshold. Context lines are not counted.
Note: Header context (e.g., `@@ -10,3 +10,4 @@ func()`) is always
highlighted with treesitter when a parser is available.