Skip to content

x/tools/cmd/guru: implements output is strange when cursor is over the interface keyword #20003

Closed
@zmb3

Description

@zmb3

For a simple main.go file:

package main

type Fooer interface {
	Foo() string
}

type Int int

func (Int) Foo() string {
	return "foo"
}

func main() {
}

When I run an implements query with the cursor over Fooer, I get reasonable output:

$ guru -json implements main.go:#40
{
	"type": {
		"name": "github.com/zmb3/foo.Fooer",
		"pos": "/Users/zbergquist/src/github.com/zmb3/foo/main.go:3:6",
		"kind": "interface"
	},
	"to": [
		{
			"name": "github.com/zmb3/foo.Int",
			"pos": "/Users/zbergquist/src/github.com/zmb3/foo/main.go:7:6",
			"kind": "basic"
		}
	],
	"method": {
		"name": "func (Fooer).Foo() string",
		"pos": "/Users/zbergquist/src/github.com/zmb3/foo/main.go:4:2"
	},
	"to_method": [
		{
			"name": "method (Int) Foo() string",
			"pos": "/Users/zbergquist/src/github.com/zmb3/foo/main.go:9:12"
		}
	]
}

However, when the cursor is moved a few bytes to the right (over interface) the output looks much different:

$ guru -json implements main.go:#50
{
	"type": {
		"name": "interface{Foo() string}",
		"pos": "-",
		"kind": "interface"
	},
	"to": [
		{
			"name": "github.com/zmb3/foo.Fooer",
			"pos": "/Users/zbergquist/src/github.com/zmb3/foo/main.go:3:6",
			"kind": "interface"
		},
		{
			"name": "github.com/zmb3/foo.Int",
			"pos": "/Users/zbergquist/src/github.com/zmb3/foo/main.go:7:6",
			"kind": "basic"
		}
	],
	"from": [
		{
			"name": "github.com/zmb3/foo.Fooer",
			"pos": "/Users/zbergquist/src/github.com/zmb3/foo/main.go:3:6",
			"kind": "interface"
		}
	]
}

It seems like guru is now identifying the selection as an anonymous interface and not the type declaration for the Fooer interface.

I'm finding the behavior in the latter case to be difficult to build tooling around, mostly because:

  1. The type.name field is long and hard to read for anything but the most simple interfaces
  2. The extra to entry makes it seem like there is an extra interface in the program
  3. The type.pos field is no longer populated

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions