Skip to content
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/cmd/guru: no way to find functions which are assignable to (match the signature of) a function type #25165

Closed
a-h opened this issue Apr 29, 2018 · 8 comments
Labels
FeatureRequest FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@a-h
Copy link
Contributor

a-h commented Apr 29, 2018

If I define a function type:

type Printer func(s string)

And a function which accepts a Printer:

type Print(s string, p Printer) {
  p(s)
}

I'd like to be able to use guru to find methods which satisfy the Printer type's signature. I'd also be able to find any matching functions for an anonymous function signature too (e.g. var x func(s string)).

guru is often used to provide text editor features. Having the ability to discover implementations would allow being able to place a caret on p Printer, select Find implementations from the text editor options, then view a list of possible implementations to use.

I've put together an example of how this might work at https://gist.github.com/a-h/dd48a97aba7c07f988aac8e529dadf6d

(See Stackoverflow question at https://stackoverflow.com/questions/50059956/how-do-i-find-implementations-of-a-function-type/50086309#50086309)

@gopherbot gopherbot added this to the Unreleased milestone Apr 29, 2018
@bcmills
Copy link
Contributor

bcmills commented Apr 30, 2018

CC: @stamblerre @alandonovan

@stamblerre
Copy link
Contributor

This would be a nice feature and could probably become part of the existing "implements" query. If you'd like to contribute the code you wrote, feel free to send out a review. Otherwise, I'd be happy to look into adding this.

@a-h
Copy link
Contributor Author

a-h commented Jun 22, 2018

Does anyone have any interest in reviewing this on Gerrit? https://go-review.googlesource.com/c/tools/+/114800

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 12, 2019
@a-h
Copy link
Contributor Author

a-h commented Oct 15, 2021

This has been superseded by gopls, just cleaning up!

@a-h a-h closed this as completed Oct 15, 2021
@bravoecho
Copy link

Hi @a-h, would you be so kind as to point me somewhere I can find how to use this in gopls? Thank you! 🙂

@a-h
Copy link
Contributor Author

a-h commented Feb 16, 2022

Oh, I mean that gopls seems to replace guru, so there's no point updating guru any more.

Language Servers like gopls implement the LSP protocol, so the underlying Language Server Spec has to support the idea of finding implementations.

From a quick glance, it looks like the spec does support the request to go to an implementation via https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_implementation

So the code relating to the implementation would be here.

https://cs.opensource.google/go/x/tools/+/refs/tags/v0.1.9:internal/lsp/cmd/implementation.go

I expect it would be possible to use the code I wrote as a basis for an LSP implementation. I would still like the feature, but not enough to revisit this change and make it happen. Maybe if I had a nice long holiday...

@a-h
Copy link
Contributor Author

a-h commented Feb 16, 2022

Just to be clear, I'm not sure if gopls supports the feature of finding functions which match the function type. In fact, I don't think it does.

@bravoecho
Copy link

I see what you mean, thank you for clarifying and pointing to the related resources.

@golang golang locked and limited conversation to collaborators Feb 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants