Skip to content

fix(highlight): use file context for header text treesitter parsing#197

Merged
barrettruth merged 3 commits intomainfrom
fix/header-context-highlight
Mar 20, 2026
Merged

fix(highlight): use file context for header text treesitter parsing#197
barrettruth merged 3 commits intomainfrom
fix/header-context-highlight

Conversation

@barrettruth
Copy link
Owner

Problem

highlight_text parsed header context text (e.g., end in @@ ... @@ end) in isolation. Without surrounding code, treesitter produced ERROR nodes for tokens like end, leaving them unhighlighted.

Solution

Prepend hunk.context_before lines (already computed by compute_hunk_context) to the treesitter parse string in highlight_text. Only captures on the target row produce extmarks. Gated by the existing highlights.context.enabled config.

Problem: the `@@ ... @@ end` header context text was parsed by
treesitter in isolation. Without surrounding code, tokens like `end`
produce ERROR nodes and get no highlight captures.

Solution: prepend `hunk.context_before` lines (already computed by
`compute_hunk_context`) to give the treesitter string parser enough
scope to recognize keywords, closing delimiters, etc. Only captures
on the target row produce extmarks.
@barrettruth barrettruth force-pushed the fix/header-context-highlight branch from 43ac94f to 961037d Compare March 20, 2026 00:23
@barrettruth barrettruth merged commit 790e92e into main Mar 20, 2026
8 checks passed
@barrettruth barrettruth deleted the fix/header-context-highlight branch March 20, 2026 00:37
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.

1 participant