-
Notifications
You must be signed in to change notification settings - Fork 805
fix(2426): goToDefinition for pattern ambient module no longer goes to implementation #2429
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
69c1134
fix(2426): extend go to def locations with reference target
a-tarasyuk c950912
add chompLeadingSpace to align with Strada behavior
a-tarasyuk 27636da
Merge branch 'main' of https://github.com/microsoft/typescript-go int…
a-tarasyuk 258bf90
cleanup
a-tarasyuk 90de837
Merge branch 'main' of https://github.com/microsoft/typescript-go int…
a-tarasyuk de12c6c
update tests to align with Strada behavior
a-tarasyuk c110412
Merge branch 'main' into fix/2426
a-tarasyuk eba128c
Merge branch 'main' into fix/2426
a-tarasyuk a3a34b9
update failingTests.
a-tarasyuk 2043ab7
Merge branch 'fix/2426' of https://github.com/a-tarasyuk/typescript-g…
a-tarasyuk c100148
cleanup
a-tarasyuk ddf0534
Merge branch 'main' of https://github.com/microsoft/typescript-go int…
a-tarasyuk f4250d8
Merge branch 'main' of https://github.com/microsoft/typescript-go int…
a-tarasyuk 00cbeb4
update manualTests
a-tarasyuk e9f24f6
update manualTests
a-tarasyuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "github.com/microsoft/typescript-go/internal/checker" | ||
| "github.com/microsoft/typescript-go/internal/collections" | ||
| "github.com/microsoft/typescript-go/internal/core" | ||
| "github.com/microsoft/typescript-go/internal/ls/lsconv" | ||
| "github.com/microsoft/typescript-go/internal/lsp/lsproto" | ||
| "github.com/microsoft/typescript-go/internal/scanner" | ||
| ) | ||
|
|
@@ -22,24 +23,31 @@ func (l *LanguageService) ProvideDefinition( | |
| clientSupportsLink := caps.TextDocument.Definition.LinkSupport | ||
|
|
||
| program, file := l.getProgramAndFile(documentURI) | ||
| node := astnav.GetTouchingPropertyName(file, int(l.converters.LineAndCharacterToPosition(file, position))) | ||
| pos := int(l.converters.LineAndCharacterToPosition(file, position)) | ||
| node := astnav.GetTouchingPropertyName(file, pos) | ||
| reference := getReferenceAtPosition(file, pos, program) | ||
|
|
||
| if node.Kind == ast.KindSourceFile { | ||
| return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{}, nil | ||
| } | ||
|
|
||
| originSelectionRange := l.createLspRangeFromNode(node, file) | ||
| if reference != nil && reference.file != nil { | ||
| return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, []*ast.Node{}, reference), nil | ||
| } | ||
|
|
||
| c, done := program.GetTypeCheckerForFile(ctx, file) | ||
| defer done() | ||
|
|
||
| if node.Kind == ast.KindOverrideKeyword { | ||
| if sym := getSymbolForOverriddenMember(c, node); sym != nil { | ||
| return l.createLocationsFromDeclarations(originSelectionRange, clientSupportsLink, sym.Declarations), nil | ||
| return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, sym.Declarations, nil /*reference*/), nil | ||
| } | ||
| } | ||
|
|
||
| if ast.IsJumpStatementTarget(node) { | ||
| if label := getTargetLabel(node.Parent, node.Text()); label != nil { | ||
| return l.createLocationsFromDeclarations(originSelectionRange, clientSupportsLink, []*ast.Node{label}), nil | ||
| return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, []*ast.Node{label}, nil /*reference*/), nil | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -52,7 +60,7 @@ func (l *LanguageService) ProvideDefinition( | |
|
|
||
| if node.Kind == ast.KindReturnKeyword || node.Kind == ast.KindYieldKeyword || node.Kind == ast.KindAwaitKeyword { | ||
| if fn := ast.FindAncestor(node, ast.IsFunctionLikeDeclaration); fn != nil { | ||
| return l.createLocationsFromDeclarations(originSelectionRange, clientSupportsLink, []*ast.Node{fn}), nil | ||
| return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, []*ast.Node{fn}, nil /*reference*/), nil | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -63,7 +71,7 @@ func (l *LanguageService) ProvideDefinition( | |
| nonFunctionDeclarations := core.Filter(slices.Clip(declarations), func(node *ast.Node) bool { return !ast.IsFunctionLike(node) }) | ||
| declarations = append(nonFunctionDeclarations, calledDeclaration) | ||
| } | ||
| return l.createLocationsFromDeclarations(originSelectionRange, clientSupportsLink, declarations), nil | ||
| return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, declarations, reference), nil | ||
| } | ||
|
|
||
| func (l *LanguageService) ProvideTypeDefinition( | ||
|
|
@@ -93,10 +101,10 @@ func (l *LanguageService) ProvideTypeDefinition( | |
| declarations = core.Concatenate(getDeclarationsFromType(typeArgument), declarations) | ||
| } | ||
| if len(declarations) != 0 { | ||
| return l.createLocationsFromDeclarations(originSelectionRange, clientSupportsLink, declarations), nil | ||
| return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, declarations, nil /*reference*/), nil | ||
| } | ||
| if symbol.Flags&ast.SymbolFlagsValue == 0 && symbol.Flags&ast.SymbolFlagsType != 0 { | ||
| return l.createLocationsFromDeclarations(originSelectionRange, clientSupportsLink, symbol.Declarations), nil | ||
| return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, symbol.Declarations, nil /*reference*/), nil | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -121,13 +129,34 @@ type fileRange struct { | |
| fileRange core.TextRange | ||
| } | ||
|
|
||
| func (l *LanguageService) createLocationsFromDeclarations( | ||
| func (l *LanguageService) createDefinitionLocations( | ||
| originSelectionRange *lsproto.Range, | ||
| clientSupportsLink bool, | ||
| declarations []*ast.Node, | ||
| reference *refInfo, | ||
| ) lsproto.DefinitionResponse { | ||
| locations := make([]*lsproto.LocationLink, 0, len(declarations)) | ||
| locations := make([]*lsproto.LocationLink, 0) | ||
| locationRanges := collections.Set[fileRange]{} | ||
|
|
||
| if reference != nil { | ||
| targetRange := lsproto.Range{ | ||
| Start: lsproto.Position{ | ||
| Line: 0, | ||
| Character: 0, | ||
| }, | ||
| End: lsproto.Position{ | ||
| Line: 0, | ||
| Character: 0, | ||
| }, | ||
| } | ||
a-tarasyuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| locations = append(locations, &lsproto.LocationLink{ | ||
| OriginSelectionRange: originSelectionRange, | ||
| TargetUri: lsconv.FileNameToDocumentURI(reference.fileName), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this ever need to go through the source mapper? |
||
| TargetRange: targetRange, | ||
| TargetSelectionRange: targetRange, | ||
| }) | ||
| } | ||
|
|
||
| for _, decl := range declarations { | ||
| file := ast.GetSourceFileOfNode(decl) | ||
| fileName := file.FileName() | ||
|
|
@@ -146,10 +175,11 @@ func (l *LanguageService) createLocationsFromDeclarations( | |
| }) | ||
| } | ||
| } | ||
| if !clientSupportsLink { | ||
| return createLocationsFromLinks(locations) | ||
|
|
||
| if clientSupportsLink { | ||
| return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{DefinitionLinks: &locations} | ||
| } | ||
| return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{DefinitionLinks: &locations} | ||
| return createLocationsFromLinks(locations) | ||
| } | ||
|
|
||
| func createLocationsFromLinks(links []*lsproto.LocationLink) lsproto.DefinitionResponse { | ||
|
|
||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.