feat(highlight): wire highlights.context into treesitter pipeline (#151)
Some checks are pending
luarocks / quality (push) Waiting to run
luarocks / publish (push) Blocked by required conditions

## Problem

`highlights.context.enabled` and `highlights.context.lines` were
defined, validated, and range-checked but never read during
highlighting. Hunks inside incomplete constructs (e.g., a table literal
or function body whose opening is beyond the hunk's own context lines)
parsed incorrectly because treesitter had no surrounding code.

## Solution

`compute_hunk_context` in `init.lua` reads the working tree file using
the hunk's `@@ +start,count @@` line numbers to collect up to `lines`
(default 25) surrounding code lines in each direction. Files are read
once via `io.open` and cached across hunks in the same file.
`highlight_treesitter` in `highlight.lua` accepts an optional context
parameter that prepends/appends context lines to the parse string and
offsets capture rows by the prefix count, so extmarks only land on
actual hunk lines. Wired through `highlight_hunk` for the two
code-language treesitter calls (not headers, not `highlight_text`, not
vim syntax).

Closes #148.
This commit is contained in:
Barrett Ruth 2026-03-05 11:14:31 -05:00 committed by GitHub
parent 29e624d9f0
commit e7d56e3bbe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 534 additions and 17 deletions

View file

@ -15,6 +15,8 @@
---@field prefix_width integer
---@field quote_width integer
---@field repo_root string?
---@field context_before string[]?
---@field context_after string[]?
local M = {}