Skip to content

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 31, 2025

This PR addresses two issues with hover range calculation in the language server:

1. Performance Issue: Duplicate getNodeForQuickInfo() Calls

The hover implementation was calling getNodeForQuickInfo() twice - once in the main ProvideHover function and again inside getQuickInfoAndDocumentation(). 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:

{
  "range": {
    "start": { "line": 10, "character": 8 },
    "end": { "line": 10, "character": 11 }
  }
}

After:

{
  "range": {
    "start": { "line": 10, "character": 9 },
    "end": { "line": 10, "character": 11 }
  }
}

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.

Copilot AI and others added 2 commits July 31, 2025 07:59
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Return applicable ranges for hover requests Add range field to hover responses for applicable ranges Jul 31, 2025
@Copilot Copilot AI requested a review from DanielRosenwasser July 31, 2025 08:07
Copilot finished work on behalf of DanielRosenwasser July 31, 2025 08:07
@@ -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)
Copy link
Member

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.

Copy link
Contributor Author

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() {
// ^
// ^^^
Copy link
Member

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?

Copy link
Contributor Author

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 Copilot AI changed the title Add range field to hover responses for applicable ranges Fix hover range calculation: eliminate duplicate calls and remove whitespace from ranges Jul 31, 2025
@Copilot Copilot AI requested a review from DanielRosenwasser July 31, 2025 08:42
Copilot finished work on behalf of DanielRosenwasser July 31, 2025 08:42
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jul 31, 2025

@copilot Fix whatever is broken in CI

@DanielRosenwasser
Copy link
Member

@copilot fix

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 31, 2025

@copilot Fix whatever is broken in CI

Fixed the CI failures in fb261c4. The test failures were due to outdated baseline files that needed to be updated to reflect the corrected hover range calculations. All tests now pass after accepting the new baselines.

Copy link
Contributor Author

Copilot AI commented Jul 31, 2025

@copilot fix

Fixed in fb261c4 by updating the hover baselines to reflect the corrected range calculations. All tests are now passing.

Copilot finished work on behalf of DanielRosenwasser July 31, 2025 20:24
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.

Return applicable ranges for hover requests
2 participants