-
Notifications
You must be signed in to change notification settings - Fork 853
Add "Go to Interfaces" counterpart of "Go to Implementations" #2037
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
Comments
Does type hierarchy not serve this purpose? |
Good point. Gopls doesn't implement that operation, but perhaps it should. Nonetheless, it wouldn't really undermine the motivation for this feature. For the same reasons VS Code has distinct operations for "Go to definition" and "Go to References" with keybindings for rapid navigation, similar control would be beneficial for quickly navigating types. |
I agree with @HighCommander4 that the upwards direction should be handled by a type hierarchy request. @adonovan can you give that a try and see how it goes. |
Provide additional information. For clangd(C++), you can click the For example: struct A {
virtual void foo() = 0;
};
struct B : A {
void foo() override {}
};
struct C : A {
void foo() final {}
}; If trigger |
Not easily, because gopls doesn't implement Type Hierarchy. Unlike every other conceivable feature, no one seems to have requested it yet, oddly; and it is unfortunately not trivial to implement because it requires some subtle changes to our filesystem-based workspace index. But why the asymmetry? Why should a downward query from an interface have its own command, but not an upward query from a concrete type--necessitating such hacks as inferring the direction of the query from the concreteness of the initial type, as gopls does, or from the adjacent |
This change causes gopls to report subinterfaces among the response to an "implementation" query on an interface type. For example, implementation(io.Reader) will now report io.ReadCloser, where previously it was discarded because it was not a concrete type. (It will also return other interface types that are identical to Reader.) From the Interfaces RPC, there is no way to request a supertypes query starting at an interface (e.g. from ReadCloser to Reader); see microsoft/language-server-protocol#2037. Use the Type Hierarchy's Supertypes RPC in this case. + test, doc, relnotes Fixes golang/go#68641 Change-Id: Ia5cc42a5ea160a4e74dc801e41f5fe3209ecd6f2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/619719 Reviewed-by: Robert Findley <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Commit-Queue: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
Background: The "Go to Implementations" feature of VS Code, which corresponds to the
textDocument/implementation
LSP request, is defined to return all the concrete implementations of a given interface or abstract type. In other words, the query is inherently "downwards" with respect to the type hierarchy.The corresponding "upwards" query is equally useful. In some LSP servers, such as gopls for Go, the behavior of this feature depends on the concreteness of the queried type. If it's an interface, the response includes types that may be assigned to it: concrete and interface types with equal or greater methods sets. If it's a concrete type, the response includes only interfaces to which the queried type may be assigned. This unfortunately leaves the user with no way to ask the question "what are the superinterfaces of this interface?", or, in Java terms, "what are the superclasses of this abstract class"? In Java there is at least the option to traverse the
implements
relation, which is explicitly declared, but in Go there is no syntactic relationship betweenimplements
-related types, making tooling even more important.Proposal: we propose to add a corresponding "Go to Interfaces" (or perhaps "supertypes") feature to VS Code that would make a similar
textDocument/implementation
query with opposite directionality. At the LSP protocol level, this would be indicated by an optionalupwards boolean
in thetextDocument/implementation
request indicating that the direction of the query is reversed from the usual downwards behavior represented by null or false.The text was updated successfully, but these errors were encountered: