fix(highlight): trim whitespace from capture spans#84
Merged
Conversation
Node-level grammar captures style their full byte range, so a capture spanning a whole statement (such as Fortran's `(program_statement)` matched as `@keyword`) bleeds styling onto the structural spaces and newlines between its children. In styled themes this underlines or bolds whitespace and line breaks. Trim leading and trailing whitespace from the final styled spans, dropping whitespace-only ones, so they fall back to the unstyled gap path. Gate the trim on the capture name: `string`, `comment`, and `character` own their whitespace and are left untouched. Rewrite three samples that were invalid source, which put the tree-sitter parser into error recovery and garbled the output: an invalid parametric struct in `fib.jl`, keyless datetimes in `config.toml`, and statement fragments in `hello.f90` (now a valid module, program, and subroutine). Regenerate the affected references.
The composite trimming testset used a valid `struct Foo`, which the Julia grammar highlights entirely through leaf captures. Its assertions pass without the trimming in `highlight_tokens`, so it did not guard the fix. Replace the input with cases verified to bleed when trimming is removed: a Fortran program whose statements are captured whole as `@keyword`, a MATLAB multi-assignment that yields a whitespace-only `@variable` capture, and invalid Julia source that drives tree-sitter error recovery into multi-line `@type` spans. The error-recovery case also restores coverage lost when the samples were rewritten as valid source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Node-level grammar captures style their full byte range, so a capture spanning a whole statement (such as Fortran's
(program_statement)matched as@keyword) bleeds styling onto the structural spaces and newlines between its children. In styled themes this underlines or bolds whitespace and line breaks.Trim leading and trailing whitespace from the final styled spans, dropping whitespace-only ones, so they fall back to the unstyled gap path. Gate the trim on the capture name:
string,comment, andcharacterown their whitespace and are left untouched.Rewrite three samples that were invalid source, which put the tree-sitter parser into error recovery and garbled the output: an invalid parametric struct in
fib.jl, keyless datetimes inconfig.toml, and statement fragments inhello.f90(now a valid module, program, and subroutine). Regenerate the affected references.Add regression tests for the trim: unit cases for
trim_capture, plus inputs verified to bleed without it (a Fortran program captured whole as@keyword, a MATLAB multi-assignment yielding a whitespace-only@variablespan, and invalid Julia source that drives error recovery, restoring the coverage the sample rewrites removed).