-
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 module-local implementation request #32973
Comments
As this feature is very valuable for my everyday development process I want to work on it if maintainers do not have any reasons against it. |
@litleleprikon: If you are interested in working on this feature, please go ahead! We will be happy to review any CLs. |
@stamblerre that response was cutting a corner a bit :) because I think it gave a false sense of how difficult it is to implement :P But then again I could be totally wrong here The good news I think is we can copy paste stuff from godoc src code who apparently has this feature already https://golang.org/lib/godoc/analysis/help.html Would appreciate for example more specific references to parts in the gopls source code to take a look at that may help in the right direction. Also some references in the source code where godoc analysis (see link above) does it's And maybe some CL boilerplate so somebody calling this feature can already see "Hello world" appearing as ouput and basically has a crash course example how gopls works and know where to start by just looking at the boilerplate CL code provided |
A lot of the code for this feature can actually be taken from guru, which has an implements feature (see https://github.com/golang/tools/blob/master/cmd/guru/implements.go). I intend to compile a document that explains how to begin contributing to For those with specific questions, I'm available via Slack on the |
Actually, the author of |
I think the
I've tried this and it seems to work just like "go to defintion". So, not what we want. Or probably it just doesn't work that well, and it falls back to "go to definition" if no implementation is found. In any case, from a quick glance,
This should be optimized so that gopls indexes this stuff, ie. as gopls typechecks (which I guess doesn't happen in every request, but incrementally in every file change), keep mappings from:
And direct requests to those mappings. That tells us which types/values could implement a type. Alternatively, or additionally, it might be interesting to keep track of which values are actually assigned to the type. So, if you do this: /* myfile.go:13 */ type myImpl struct { ... } // implements MyInterface
/* myfile.go:42 */ var i MyInterface = myImpl{} then a This may be more interesting than the find-all-possible-implementors approach because if an interface or function is simple enough, many types may implement it accidentally, while only in a few places we find actual implementations. E. g.: type Decoder func(interface{}) error
func Foo(decoder Decoder) { ... }
// actually create a Decoder value, so return this position in a `implementation`
// response
Foo(func(interface{}) error {
...
})
// this function could also be used as a Decoder, but it isn't, and it would be
// noisy that it shows up in an `implementation` response
func Inspect(interface{}) error What do you think? |
Hi everyone in this chat! Thank you all for your suggestions. Excuse me for long silence. For personal reasons I had a lack of time but now I am ready to continue development of this feature. @tcard I think your suggestion is pretty good and caching types and implementations will reduce the time for implementations search. I am right now not sure about a ways how to implement it and probably I need some time to be more familiar with caching in gopls. |
Change https://golang.org/cl/203918 mentions this issue: |
@stamblerre thanks for merging this!
Example code: package main
import "fmt"
type SomeInterface interface {
SomeFunc() error
}
type someImpl struct{}
func (i *someImpl) SomeFunc() error { return nil }
func main() {
var i SomeInterface
i = &someImpl{}
fmt.Println(i.SomeFunc())
} Calling
|
For me it doesn't work. How do I enable this feature? |
@inliquid you need to update |
@nezorflame thanks, I'm on latest from |
@inliquid is the implementation of this interface in the same package? |
Yes sure, I edited comment. |
@inliquid: If you add the following your VSCode settings, you should see more detailed logging. Could you add those logs to this issue? Thanks! "go.languageServerFlags": [
"serve",
"-rpc.trace",
] |
Change https://golang.org/cl/206150 mentions this issue: |
Change https://golang.org/cl/206150 will fix the second of @nezorflame's bullet points (implements on interface functions). I plan to work on implementations across packages (but still only within the same workspace) next week. |
This change copies the code in guru's implements implementation that finds implementations of methods over to gopls, and uses the information determined to resolve implements requests on methods. Implements still only works only within packages. Updates golang/go#32973 Change-Id: I0bd7849a9224fbef7ab8385070b18fbb30703e2b Reviewed-on: https://go-review.googlesource.com/c/tools/+/206150 Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Change https://golang.org/cl/206518 mentions this issue: |
Change https://golang.org/cl/206518 will fix the first of @nezorflame's bullet points (implements across packages in the same module). For it to work the LSP needs to be given the entire module as its View/workspace. |
The change has been submitted. Please try it out and let me know if you encounter any issues. Thanks!! |
Is there any way to find which interface does some type implement? This worked fine with |
@inliquid: Was |
No idea. It worked very well when both invoking |
Great, works like a charm. Is there a tracking issue for the workspace-wide work? |
This has been submitted as of this CL. You will have to rebuild |
@stamblerre thank you! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Trying to get implementations of interface in go
What did you expect to see?
gopls returns the list of places with structures which implements interface
What did you see instead?
textDocument/implementation
request is not implementedThe text was updated successfully, but these errors were encountered: