Skip to content

x/tools/gopls: extend gopls type def to []location #76723

@h9jiang

Description

@h9jiang

gopls version

head

go env

N/A

What did you do?

Execute type definition

What did you see happen?

When the request location is pointing a function,

func() (foo, bar, error) gopls return "no type definition"

func() (foo, error) gopls return location to foo

func() (error) gopls return "no type definition"

#38589 mentions, gopls will ignore the error return value. The typeToObject function also only return one typeName even if multiples could be available.

What did you expect to see?

func() (foo, bar, error) gopls return locations to "foo", "bar", "error"

func() (foo, error) gopls return location to "foo", "error"

func() (error) gopls return "error"

the user can choose which type he/she want to jump to. The LSP type def support return []location.

Editor and settings

While introducing the range into TextDocumentPositionParam, I noticed that the type def method also extends TextDocumentPositionParam. So it is very intuitive idea to return type definition of an expression.

time.Now().Add(time.Second).String()

User can select a sub expression in the expression above and query "TypeDef". Some expression have multiple return values so the return type of a given expression is "types.Tuple". I wonder if it is possible to return the slice of location when the expression evaluates to a tuple.

Is there any reason for return only one location. (I understand if the language server only return one location, the language client will simply take user directly to the location without asking user "where you want to go among all these X types?")

@adonovan

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    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