Skip to content

x/tools/gopls: cannot find refs to function type #62366

@notrobpike

Description

@notrobpike

What version of Go are you using (go version)?

$ go version
go version go1.20.7 darwin/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOHOSTARCH="amd64"
GOHOSTOS="darwin"

What did you do?

I tried to use vscode to "find all references", "find all implementations", "go to definition" of an function type alias embedded in a struct. vscode is unable to find it. vscode uses gopls so I believe it is gopls that is at fault.

What did you expect to see?

I expected to be taken to the method that the type alias references.

What did you see instead?

"go to definition" took me to the method that the function alias was itself part of (where it was being called from).

Load the following program into vscode. right click on the commented function call and try to find what actually would get called.

package main

import (
	"context"
	"fmt"
)

type cmdable func(ctx context.Context, arg string) string

type client struct {
	cmdable
}

func (c *client) init() {
	c.cmdable = c.Process
}

func (c *client) Process(ctx context.Context, arg string) string {
	return arg
}

func (c cmdable) DoIt(ctx context.Context, arg string) string {
	return c(ctx, arg) // really?!?
}

func main() {
	var c client
	c.init()
	fmt.Println(c.DoIt(context.Background(), "wtf"))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions