Skip to content

x/tools/gopls: support global "go to implementation" queries on function types [local is done] #56572

Open

Description

@a-h

As of gopls v0.10.1, the go to implementation feature of the LSP supports finding all of the types which implement an interface via the "Go to Implementation" feature in VS Code and Neovim etc.

This is a feature request to add the same support for named function types, and anonymous functions.

Current behaviour

go_to_implementation_interface.mov

Go also allows you to define function types and also accept functions as a parameter. This is seen in the standard library, e.g. https://pkg.go.dev/net/http#HandlerFunc and https://pkg.go.dev/strings#IndexFunc but here's a simple example.

type FunctionType func(s string, i int)

Any function that has the same signature implements that function type.

func ImplementationOfFunctionType1(s string, i int) {
}

func ImplementationOfFunctionType2(s string, i int) {
}

So, you can use it like this:

func TestFunctionType(f FunctionType) {
	f("s", 0)
}

The current behaviour of gopls does not allow you to go to the implementation of f from within the function body of the TestFunctionType function.

go_to_implementation_function_current.mov

And this same behaviour is true of anonymous functions:

go_to_implementation_function_anon_current.mov

Expected behavior

It should be possible to go the functions which implement the signature, as per this example.

go_to_function_type_implementation.mov

I've also tested the same behaviour with my modified version of the gopls Language Server running with Neovim.

Implementation

I've got an implementation of the functionality to contribute.

Activity

  1. added
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    goplsIssues related to the Go language server, gopls.
    on Nov 4, 2022
  2. added this to the Unreleased milestone on Nov 4, 2022
  3. findleyr commented on Nov 4, 2022

    @findleyr
    Contributor

    Hi, if you already have an implementation for this, we can take a look. As long as it is not too invasive, this is a feature we'd happily accept. Thanks!

  4. a-h commented on Nov 4, 2022

    @a-h
    ContributorAuthor

    Thanks @findleyr - I've added a PR over here: golang/tools#412

    I've tried to keep the new features out of the way as much as possible.

  5. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Jul 13, 2024
  6. gopherbot commented on Oct 9, 2024

    @gopherbot
    Contributor

    Change https://go.dev/cl/619195 mentions this issue: gopls/internal/golang: allow Implementation on any expression

  7. gopherbot commented on Mar 4, 2025

    @gopherbot
    Contributor

    Change https://go.dev/cl/654556 mentions this issue: gopls/internal/golang: Implementations for func types

  8. gopherbot commented on Mar 5, 2025

    @gopherbot
    Contributor

    Change https://go.dev/cl/655175 mentions this issue: gopls/internal/util/fingerprint: split from cache/methodsets

  9. 1 remaining item

  10. adonovan commented on Jun 4, 2025

    @adonovan
    Member

    This was implemented in the local (same-package) case by CL 654556. The global case remains unaddressed.

  11. changed the title [-]x/tools/gopls: support "go to implementation" (textDocument/implementation) for function types[/-] [+]x/tools/gopls: support global "go to implementation" queries on function types [local is done][/+] on Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

DocumentationIssues describing a change to documentation.FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.help wanted

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions