Conversation
highlightRegion located the region's end inside the region's own slice of the line, but compared that line-relative index against the region's absolute start offset. When the two happened to be equal, searchNesting was cleared and every rule inside the region was skipped, leaving the contents with the region's own group. This is visible on master today: in a C file, 'int a;// TODO: x' does not highlight the TODO, while 'int ab;// TODO: x' does, purely because of the offsets involved. Compare against the start of the slice instead, and add a regression test covering a region starting at every offset on the line.
Contributor
Author
|
Closing this as a duplicate — I missed that #4022 already fixes it (and that #4018 tracks it). #4022 has the same I've offered the regression test from here over on #4022, since that PR has no tests and the open question there was whether it breaks anything else. Sorry for the noise. |
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.
highlightRegionfinds the region's end inside the region's own slice of the line, but compares that line-relative index against the region's absolute start offset:When the two happen to be equal,
searchNestingis cleared and every rule inside the region is skipped, so the region's contents keep the region's own group.This is visible on master today, with no other changes — in a C file:
int a;// TODO: xint ab;// TODO: xThe only difference is the offsets: the comment region starts at 8 and its remaining slice
TODO: xis also 8 long, so the comparison matches by coincidence and thetodorule never runs. Any region with inner rules can hit this at some start offset.Comparing against the start of the slice (
endLoc[0] == 0) preserves the intent — "the region ends immediately, so there is nothing inside it to search" — without mixing coordinate systems.Added a regression test that puts a region at every start offset on the line and checks its inner rule still applies; it fails at offset 3 before the change.
pkg/highlighthad no tests, so this adds the file.Found while working on #4236, where the C
#includeregion made it show up often (#includeis exactly the length that collides with short header names).