fix(highlight): prevent duplicate extmarks from two-pass rendering

Problem: the deferred pass (pass 2) cleared the hunk range and called
`highlight_hunk` with full opts, reapplying line backgrounds, intra-line
diffs, prefix DiffsClear, and per-char prefix highlights that pass 1
already set. This doubled extmark counts on affected lines.

Solution: add `syntax_only` flag to `diffs.HunkOpts`. When set,
`highlight_hunk` skips non-syntax extmarks (line backgrounds, intra-line,
prefix DiffsClear, per-char prefix fg, hide_prefix overlay, conflict
markers). The deferred pass uses `syntax_only = true` and no longer
clears the namespace range, so pass 1's extmarks persist while pass 2
layers treesitter and content DiffsClear on top.
This commit is contained in:
Barrett Ruth 2026-03-05 01:27:00 -05:00
parent 91a856443f
commit a26e9a522c
3 changed files with 200 additions and 79 deletions

View file

@ -797,18 +797,13 @@ local function init()
return
end
local t1 = config.debug and vim.uv.hrtime() or nil
local full_opts = {
local syntax_opts = {
hide_prefix = config.hide_prefix,
highlights = config.highlights,
syntax_only = true,
}
for _, hunk in ipairs(deferred_syntax) do
local start_row = hunk.start_line - 1
local end_row = hunk.start_line + #hunk.lines
if hunk.header_start_line then
start_row = hunk.header_start_line - 1
end
vim.api.nvim_buf_clear_namespace(bufnr, ns, start_row, end_row)
highlight.highlight_hunk(bufnr, ns, hunk, full_opts)
highlight.highlight_hunk(bufnr, ns, hunk, syntax_opts)
end
if t1 then
dbg('deferred pass: %d hunks in %.2fms', #deferred_syntax, (vim.uv.hrtime() - t1) / 1e6)