-
Notifications
You must be signed in to change notification settings - Fork 763
Implement Go To Implementations command #1430
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,14 +128,10 @@ func newNodeEntryWithKind(node *ast.Node, kind entryKind) *referenceEntry { | |
|
|
||
| func newNodeEntry(node *ast.Node) *referenceEntry { | ||
| // creates nodeEntry with `kind == entryKindNode` | ||
| n := node | ||
| if node != nil && node.Name() != nil { | ||
| n = node.Name() | ||
| } | ||
| return &referenceEntry{ | ||
| kind: entryKindNode, | ||
| node: node, | ||
| context: getContextNodeForNodeEntry(n), | ||
| node: core.OrElse(node.Name(), node), | ||
| context: getContextNodeForNodeEntry(node), | ||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -410,22 +406,53 @@ func (l *LanguageService) ProvideReferences(params *lsproto.ReferenceParams) []* | |
|
|
||
| symbolsAndEntries := l.getReferencedSymbolsForNode(position, node, program, program.GetSourceFiles(), options, nil) | ||
|
|
||
| return core.FlatMap(symbolsAndEntries, l.convertSymbolAndEntryToLocation) | ||
| return core.FlatMap(symbolsAndEntries, l.convertSymbolAndEntriesToLocations) | ||
| } | ||
|
|
||
| func (l *LanguageService) ProvideImplementations(params *lsproto.ImplementationParams) []*lsproto.Location { | ||
| program, sourceFile := l.getProgramAndFile(params.TextDocument.Uri) | ||
| position := int(l.converters.LineAndCharacterToPosition(sourceFile, params.Position)) | ||
| node := astnav.GetTouchingPropertyName(sourceFile, position) | ||
|
|
||
| var seenNodes collections.Set[*ast.Node] | ||
| var entries []*referenceEntry | ||
| queue := l.getImplementationReferenceEntries(program, node, position) | ||
|
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. The original had something like the following check before processing as a queue and idea what that was intended for? I think there was some special handling for not "cascading" beyond the direct superclass
Member
Author
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. Yeah, I think it is so that Go To Implementation on say a
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. I feel like that makes sense, though, since super is basically "do the parent class thing" and so shouldn't jump anywhere else?
Member
Author
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. Well, but what does Go To Implementation on something that isn't a type really mean to begin with? I would think of it as go-to-implementation-of-the-type-of-the-thing-i-am-on. And if the type of
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. My mental model of it is "the implementation of
Member
Author
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. In Strada, Go To Definition on a
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. Yeah I looked at the test cases and was surprised. Both go-to-definition and go-to-implementation should probably go to the constructor, but instead we go to the base class for go-to-implementation which feels like it is the less-intuitive thing.
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. weirdddd
Member
Author
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. I suppose the meaning we ascribe to "implementation" in go-to-implementations is something that implements that type. As opposed to the implementation of a method or constructor. |
||
| for len(queue) != 0 { | ||
| entry := queue[0] | ||
| queue = queue[1:] | ||
| if !seenNodes.Has(entry.node) { | ||
| seenNodes.Add(entry.node) | ||
| entries = append(entries, entry) | ||
| queue = append(queue, l.getImplementationReferenceEntries(program, entry.node, entry.node.Pos())...) | ||
| } | ||
| } | ||
|
|
||
| return l.convertEntriesToLocations(entries) | ||
| } | ||
|
|
||
| func (l *LanguageService) getImplementationReferenceEntries(program *compiler.Program, node *ast.Node, position int) []*referenceEntry { | ||
| options := refOptions{use: referenceUseReferences, implementations: true} | ||
| symbolsAndEntries := l.getReferencedSymbolsForNode(position, node, program, program.GetSourceFiles(), options, nil) | ||
| return core.FlatMap(symbolsAndEntries, func(s *SymbolAndEntries) []*referenceEntry { return s.references }) | ||
| } | ||
|
|
||
| // == functions for conversions == | ||
| func (l *LanguageService) convertSymbolAndEntryToLocation(s *SymbolAndEntries) []*lsproto.Location { | ||
| var locations []*lsproto.Location | ||
| for _, ref := range s.references { | ||
| if ref.textRange == nil { | ||
| sourceFile := ast.GetSourceFileOfNode(ref.node) | ||
| ref.textRange = l.getRangeOfNode(ref.node, sourceFile, nil /*endNode*/) | ||
| ref.fileName = sourceFile.FileName() | ||
| func (l *LanguageService) convertSymbolAndEntriesToLocations(s *SymbolAndEntries) []*lsproto.Location { | ||
| return l.convertEntriesToLocations(s.references) | ||
| } | ||
|
|
||
| func (l *LanguageService) convertEntriesToLocations(entries []*referenceEntry) []*lsproto.Location { | ||
| locations := make([]*lsproto.Location, len(entries)) | ||
| for i, entry := range entries { | ||
| if entry.textRange == nil { | ||
| sourceFile := ast.GetSourceFileOfNode(entry.node) | ||
| entry.textRange = l.getRangeOfNode(entry.node, sourceFile, nil /*endNode*/) | ||
| entry.fileName = sourceFile.FileName() | ||
| } | ||
| locations[i] = &lsproto.Location{ | ||
| Uri: FileNameToDocumentURI(entry.fileName), | ||
| Range: *entry.textRange, | ||
| } | ||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| locations = append(locations, &lsproto.Location{ | ||
| Uri: FileNameToDocumentURI(ref.fileName), | ||
| Range: *ref.textRange, | ||
| }) | ||
| } | ||
| return locations | ||
| } | ||
|
|
||
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 like it's going to end up biting us at some point when we forget to add a case here; is this required?
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.
Alternatively,
Type()(panics) andTryGetType()/TypeOrNil()(returnsnil)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.
Well, other than that some nil returning is actually intentional IIRC
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.
Type()is already optional and we already have logic that always returnsnilfor some node kinds. Seems fine to just allow it for any node kind.Name()is similar already.