-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: improve the 'implementation' query on interfaces #68641
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
Thanks for the bug report; I can reproduce it with your test case. (The functions According to the documentation, implementation(A) should indeed include B, since B implements A, so this is definitely a bug. However, implementation(B) is correct not to include A, since A does not implement B. type A interface { // impls={X} (should include B)
Read([]byte) (int, error)
}
type B interface { // impls={} (correct)
Read([]byte) (int, error)
Extra()
}
type X int // impls={A} (correct)
func (x X) Read([]byte) (int, error) { return 0, nil } |
Thanks for your reply.
I understand that this is true according to the documentation, but could we change this? What I was trying to show in In other words, concrete types can only implement, but interfaces can both implement and be implemented. I understand that the |
@adonovan Is this a problem I can try to fix? I've been idle lately. 0.0 |
Certainly we could, and potentially even within the existing
If you're referring to the bug portion of the issue (that implementations(A) should include B), then yes, we would welcome a fix. Thanks. |
Change https://go.dev/cl/603075 mentions this issue: |
![]() |
Based on the description of the Go to Implementation feature in the VS Code manual, and despite my comment in the source, I'm no longer convinced that the gopls behavior is wrong. The manual says that when triggered by an interface type, it reports concrete types (subtypes), and when triggered by a concrete type, it reports interfaces (supertypes). That's what gopls does. Of course, in Go, interfaces may have supertypes (also interfaces). And in languages like Java, concrete types may have subtypes (also concrete types). It would be useful in both these languages for LSP to separate the queries for supertypes and subtypes. But they do need to be separate queries: it makes no sense to report a mixture within a single operation. One way for LSP to do this would be to support generalized reference queries. [Update: a better one would be:] |
Change https://go.dev/cl/605395 mentions this issue: |
Change https://go.dev/cl/619719 mentions this issue: |
Change https://go.dev/cl/663055 mentions this issue: |
This CL adds basic support for the LSP Type Hierarchy feature. There are three new RPCs: - PrepareTypeHierarchy asks for a description of the currently selected text, which must be a reference to a type name. - Supertypes and Subtypes ask for the items related by the subtyping relation, using the same machinery as Implementations by method sets, which has been factored to deliver a concurrent stream of results at a higher level then just protocol.Location. Unlike Implementations, Type Hierarchy does not report relationships between func types and FuncDecl/FuncLit/RangeStmt. The names of types are now saved in the methodsets index. The marker test framework has been extended with @{super,sub}types markers. This CL also sets us up to start reporting interface/interface relationships (golang/go#68641), which are especially desirable in the Type Hierarchy viewer; but that behavior change will be left for a follow-up. + tests, docs, relnotes Fixes golang/go#72142 Change-Id: Id60c9f447e938ac7e34262522ccd79bd54d90fc5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/663055 Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Commit-Queue: Alan Donovan <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> Reviewed-by: Robert Findley <[email protected]>
gopls version
go env
What did you do?
What did you see happen?
implementation
behaves like so:What did you expect to see?
Much like the relationship between A and X, A is implemented by B, and B implements A. Therefore:
Editor and settings
No response
Logs
No response
The text was updated successfully, but these errors were encountered: