Skip to content

Support LocationLink in go-to-definition with default enablement #1490

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 6 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 31, 2025

This PR implements support for LocationLink in go-to-definition requests as specified in LSP 3.14.0+, with LocationLinks enabled by default to provide enhanced navigation experience out of the box.

Key Features

Enhanced Definition Response:
The LocationLink type provides richer information compared to basic Location:

  • originSelectionRange: The span of the queried symbol (bound span for highlighting during interaction)
  • targetRange: Full declaration range including body and comments
  • targetSelectionRange: Precise name/identifier location for navigation

Default Enablement:
LocationLink support is now enabled by default when clients don't specify definition capabilities, ensuring users get the enhanced experience without requiring explicit client configuration. Clients can still opt out by explicitly setting linkSupport: false.

Example Enhancement:

// Before: Basic Location response
{
  "uri": "file:///types.ts",
  "range": { "start": { "line": 0, "character": 17 }, "end": { "line": 0, "character": 23 } }
}

// After: Rich LocationLink response  
{
  "originSelectionRange": { "start": { "line": 2, "character": 14 }, "end": { "line": 2, "character": 20 } },
  "targetUri": "file:///types.ts",
  "targetRange": { "start": { "line": 0, "character": 0 }, "end": { "line": 3, "character": 1 } },
  "targetSelectionRange": { "start": { "line": 0, "character": 17 }, "end": { "line": 0, "character": 23 } }
}

This enables editors to provide enhanced UX like highlighting the origin span during mouse interaction and showing the full context of target declarations.

Fixes #1439.


💬 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 08:06
- Add client capability checking for DefinitionClientCapabilities.LinkSupport
- Modify ProvideDefinition to accept client capabilities parameter
- Create createDefinitionResponse function to decide between LocationLink[] and Location[]
- Implement createLocationLinksFromDeclarations with proper origin selection range
- Update fourslash test infrastructure to handle DefinitionLinks gracefully
- Add helper function getDefinitionClientCapabilities in server
- Ensure backward compatibility with existing Location[] responses

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
- Created TestLocationLinkEndToEnd to validate full functionality
- Test uses client capabilities with LinkSupport enabled
- Verifies that cross-file go-to-definition works with LocationLink format
- Demonstrates proper integration between server, client capabilities, and definition provider

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Support LocationLink in go-to-definition Support LocationLink in go-to-definition Jul 31, 2025
@Copilot Copilot AI requested a review from DanielRosenwasser July 31, 2025 08:12
Copilot finished work on behalf of DanielRosenwasser July 31, 2025 08:12
Copy link
Member

Choose a reason for hiding this comment

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

Get rid of this test, we have coverage elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the test as requested. Commit 694ad3b.

Copy link
Member

Choose a reason for hiding this comment

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

Get rid of this test, it's not a language service test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the compiler test as requested. Commit 694ad3b.

@@ -891,7 +891,14 @@ func (f *FourslashTest) VerifyBaselineGoToDefinition(
} else if result.Location != nil {
resultAsLocations = []lsproto.Location{*result.Location}
} else if result.DefinitionLinks != nil {
t.Fatalf("Unexpected definition response type at marker '%s': %T", *f.lastKnownMarkerName, result.DefinitionLinks)
// Convert DefinitionLinks to Locations for baseline comparison
resultAsLocations = make([]lsproto.Location, len(*result.DefinitionLinks))
Copy link
Member

Choose a reason for hiding this comment

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

The right thing is not to normalize to Locations. Instead, what the original code did was roughly checking if there was a single result, and if so, set the appropriate additionalSpan for getBaselineContentForFile.

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 the normalization logic to use additionalSpan for single DefinitionLink results instead of converting to Locations. Now properly sets the origin selection range as additionalSpan for baseline comparison. Commit 694ad3b.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, but switch this to use core.Map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to use core.Map instead of manual loop. Commit 0abc02d.

@DanielRosenwasser
Copy link
Member

@copilot address feedback.

…lization

- Remove internal/fourslash/tests/gen/locationlink_endtoend_test.go (coverage exists elsewhere)
- Remove testdata/tests/cases/compiler/gotoDefinitionLocationLink.ts (not a language service test)
- Fix fourslash.go to properly handle DefinitionLinks by setting additionalSpan instead of normalizing to Locations
- When single DefinitionLink with origin selection range, use it as additionalSpan for baseline comparison

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

Copilot AI commented Aug 4, 2025

@copilot address feedback.

All feedback addressed in commit 694ad3b.

@Copilot Copilot AI requested a review from DanielRosenwasser August 4, 2025 18:22
Copilot finished work on behalf of DanielRosenwasser August 4, 2025 18:22
Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

Good foundation, but you need to enable the default capabilities for definition requests and update the baselines.

@@ -891,7 +891,14 @@ func (f *FourslashTest) VerifyBaselineGoToDefinition(
} else if result.Location != nil {
resultAsLocations = []lsproto.Location{*result.Location}
} else if result.DefinitionLinks != nil {
t.Fatalf("Unexpected definition response type at marker '%s': %T", *f.lastKnownMarkerName, result.DefinitionLinks)
// Convert DefinitionLinks to Locations for baseline comparison
resultAsLocations = make([]lsproto.Location, len(*result.DefinitionLinks))
Copy link
Member

Choose a reason for hiding this comment

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

Okay, but switch this to use core.Map

@DanielRosenwasser
Copy link
Member

@copilot address feedback

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

Copilot AI commented Aug 4, 2025

@copilot address feedback

All feedback addressed in commit 0abc02d.

Copy link
Contributor Author

Copilot AI commented Aug 4, 2025

Good foundation, but you need to enable the default capabilities for definition requests and update the baselines.

Default LinkSupport capabilities enabled and baselines updated. Commit 0abc02d.

@Copilot Copilot AI changed the title Support LocationLink in go-to-definition Support LocationLink in go-to-definition with default enablement Aug 4, 2025
@Copilot Copilot AI requested a review from DanielRosenwasser August 4, 2025 20:11
Copilot finished work on behalf of DanielRosenwasser August 4, 2025 20:11
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.

Support LocationLink in go-to-definition
2 participants