-
Notifications
You must be signed in to change notification settings - Fork 674
Fix hover range calculation: eliminate duplicate calls and remove whitespace from ranges #1489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
internal/ls/hover.go
Outdated
@@ -31,6 +31,12 @@ func (l *LanguageService) ProvideHover(ctx context.Context, documentURI lsproto. | |||
if quickInfo == "" { | |||
return lsproto.HoverOrNull{}, nil | |||
} | |||
|
|||
// Calculate the applicable range for the hover | |||
rangeNode := getNodeForQuickInfo(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets called twice - once from within getQuickInfoAndDocumentation
.
In Strada, this is named as nodeForQuickInfo
. We should just calculate it above the call to getQuickInfoAndDocumentation
and get rid of the call within that function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in afe2a85 by refactoring to calculate getNodeForQuickInfo()
once in the main function and passing it through to getQuickInfoAndDocumentationWithNode()
, eliminating the duplicate call.
@@ -11,7 +11,7 @@ | |||
// * @see {@link C} its great | |||
// */ | |||
// function CC() { | |||
// ^ | |||
// ^^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems off - the range includes whitespace. Can you check what the old baseline did here and figure that out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in afe2a85 by using scanner.SkipTrivia()
to calculate the range start position without leading whitespace. The range now correctly starts at character 9 (the "C" in "CC") instead of character 8 (the space before "CC"), matching the original TypeScript behavior.
… and remove whitespace from ranges Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
@copilot Fix whatever is broken in CI |
@copilot fix |
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
This PR addresses two issues with hover range calculation in the language server:
1. Performance Issue: Duplicate
getNodeForQuickInfo()
CallsThe hover implementation was calling
getNodeForQuickInfo()
twice - once in the mainProvideHover
function and again insidegetQuickInfoAndDocumentation()
. This has been optimized by calculating the node once and passing it through the call chain.2. Range Accuracy: Whitespace Inclusion in Hover Ranges
Hover ranges were incorrectly including leading whitespace, causing editors to highlight more text than intended. For example:
Before:
After:
The fix uses
scanner.SkipTrivia()
to calculate the range start position without leading whitespace, ensuring ranges only cover the actual identifier being hovered over. This matches the behavior of the original TypeScript language server.The implementation correctly handles various language elements including function names, variable declarations, parameters, class names, and method calls. All hover tests have been updated to reflect the corrected ranges.
Fixes #1488.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.