-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/tools/gopls: improve the 'implementation' query on interfaces #68641
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: |
Too much noise? Maybe we should sort, `local.struct`>`other.struct`>`local.interface`>`local.interface` ? @adonovan |
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: |
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: