Skip to content
This repository has been archived by the owner on Nov 25, 2021. It is now read-only.

Fix off-by-one highlighting error #360

Closed
wants to merge 3 commits into from
Closed

Fix off-by-one highlighting error #360

wants to merge 3 commits into from

Conversation

efritz
Copy link
Contributor

@efritz efritz commented Apr 1, 2021

This PR fixes an off-by-one highlighting issue for all LSIF-based that was introduced (and has been present since) #331.

This fixes the behavior for me when run locally, but I'm going to delegate an actual solution to @tjkandala as there may be a better or more general solution to what's here. I'm not 100% I understand my change or a lot of the related code here. There's likely a better solution farther up or farther down the call stack, but this seems to work for a very specific use case during manual testing.

The recent merge of sourcegraph/code-intel-extensions#594 should make this problem (and subsequent fix) more apparent. We were not always returning the range data from the code intel extension. Note that we always return zero-indexed and half-closed intervals for ranges (as stated by the LSP spec).

Note that the highlighting is correct for document highlights, so this bug seems to only exist when displaying the ranges given back by the hover observable. The other observable behavior seem correct.

Screen Shot 2021-03-31 at 5 24 43 PM

Screen Shot 2021-03-31 at 11 30 43 AM

Screen Shot 2021-03-31 at 11 32 18 AM

Screen Shot 2021-03-31 at 11 34 26 AM

Screen Shot 2021-03-31 at 11 35 00 AM

@efritz efritz self-assigned this Apr 1, 2021
@codecov
Copy link

codecov bot commented Apr 1, 2021

Codecov Report

Merging #360 (1f4619b) into master (b9f113b) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #360   +/-   ##
=======================================
  Coverage   85.86%   85.86%           
=======================================
  Files          14       14           
  Lines         651      651           
  Branches      174      174           
=======================================
  Hits          559      559           
  Misses         92       92           
Impacted Files Coverage Δ
src/hoverifier.ts 85.65% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9f113b...1f4619b. Read the comment docs.

@@ -687,7 +687,7 @@ export function createHoverifier<C extends object, D, A>({
},
end: {
line: hoverOrError.range.end.line + 1,
character: hoverOrError.range.end.character + 1,
character: hoverOrError.range.end.character,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It definitely feels wrong to remove the + 1 from the character calculation but not from the line. That can't be right, and it will probably make the code more confusing/harder to debug for the next issue.

The comment above indicates that this transformation is done because the input LSP range is 0-indexed, but other parts of the code are 1-indexed.

                // The result is 0-indexed; the code view is treated as 1-indexed.

The issue here is probably more of a problem with the logic that maps the range to nodes treating the end as inclusive as opposed to exclusive, and the fix would be in that logic, as opposed to here. So something involving getTokenAtPositionOrRange() or getTokenAtPositionOrRange() probably.

BIG DISCLAIMER THAT I'M JUST GUESSING 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixfbecker I agree, and I opened this PR to get exactly this type of advice. Who knows this code well enough to be able to formulate an actual solution?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjkandala when he's back from vacation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump @tjkandala

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He's still out of office today :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjkandala have a good vacay today cuz ur gettin pinged tmr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixfbecker Looks like you're right (fix in PR #366)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants