-
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: support showing all interfaces that a given type implements #35550
Comments
@stamblerre I've run into this a couple times. I come across a concrete method and run find-references on it, but get nothing back. I'm mildly confused until I figure the method might be used to satisfy an interface, but there is no way to find that interface easily to continue my code exploration. Would you be opposed to making textDocument/implementation also work backwards from concrete type/method -> interface type/method for now? We should also explore a proposal to add "implements" to the LSP spec, but it is sort of a unique problem to Go since most languages require you to explicitly declare when a type implements an interface, so going from concrete -> interface isn't hard for the user. Personally, I don't really want another flavor of |
Yes, I think it's time to give this a try. I think it's a reasonable solution. But I think we could also try having find references include these results. |
Change https://golang.org/cl/219678 mentions this issue: |
Now "implementations" supports finding interfaces implemented by the specified concrete type. This is the inverse of what "implementations" normally does. There isn't currently a better place in LSP to put this functionality. The reverse lookup isn't an important feature for most languages because types often must explicitly declare what interfaces they implement. An argument can be made that this functionality fits better into find- references, but it is still a stretch. Plus, that would require find-references to search all packages instead of just transitive dependents. Updates golang/go#35550. Change-Id: I72dc78ef52b5bf501da2f39692e99cd304b5406e Reviewed-on: https://go-review.googlesource.com/c/tools/+/219678 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Any progress? |
The above CL has been merged at master, but it is not part of the |
Yes, it only works on packages in your module and their transitive dependencies. |
Are you sure you have the changes in your running gopls? Your example works for me, and fmt.Stringer/io.Reader also work. |
Well, I update from master every day, so I suppose this was merged few hours ago? Let me check. Is there any chance, for instance, if I ask to find implementations navigating at |
Yes, find-implementations on fmt.Stringer should list a ton of things including any types in your workspace that implement fmt.Stringer. |
Nice, finally it looks like something usable and helpful. Like it was with |
So does it work for you now? What was the problem? |
When I open this project: https://github.com/benthosdev/benthos-plugin-example It shows that there is no local type implementing it: However this type implements it: To be honest before that I saw just one single time that feature worked (but this particular type was missing as well in list of implementations of |
I can reproduce it not working when you run find-implementations on the declaration of the |
Yes, right now it's same. |
The issue is the github.com/Jeffail/benthos/v3/lib/types dependency is loaded in ParseExported mode when github.com/benthosdev/benthos-plugin-example/output is loaded, but when you run find-implementations from github.com/Jeffail/benthos/v3/lib/types/interface.go it uses the ParseFull version, so the named types in the interface no longer match. @stamblerre I guess the solution is to re-type check a package's dependents when it transitions from ParseExported to ParseFull? In other words if you directly open a file that was previously parsed in ParseExported, you need to invalidate type data of any dependent packages so they properly depend on the ParseFull version. |
Actually I don't open it directly, I just |
gopls shows unexported interfaces and implementations. Do you have steps to reproduce them not showing up? |
For example, mentioned above |
That is related to the other issue. The broker package is loaded in ParseExported mode which means the function bodies and un-exported objects are elided. That type is defined in the function body (and is unexported), so gopls can't find it. |
Is this gonna be fixed? |
Fixing the first issue of finding implementations starting from a non-workspace dependency seems relatively straight forward, but fixing the second issue will take more consideration. gopls loads non-workspace dependencies in export-only mode to reduce memory usage, which is a concern for many users. |
I understand it's not trivial. Would be nice to have it anyways, thank you. |
Ok, I got what i am missing. The references result turned normal after I moved the project into |
I think this issue falls under the broader category of figuring out how to better handle the full vs exported ASTs. This needs to be resolved in the context of running analyses correctly too, but I don't think it will happen until after |
Should this be part of the textDocument/implementation request or is this a separate feature? Perhaps we need to request clarification in the protocol.
The text was updated successfully, but these errors were encountered: