x/tools/gopls: typeDefinition: support more kinds of syntax
#67,890 opened on Jun 7, 2024
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
The LSP typeDefinition query reports the location of the definition of a type. Currently, it requires a symbol, whose type it computes, and from which it then tries to pick the most salient named type. But there are lots of other expressions for which it could give useful information:
- any expression
- a struct field
- imported package names.
gopls should support more of these.
(Unfortunately the LSP provides no way to support the "describe type" feature of the late cmd/guru, which reported the type of the selected expression: TypeDefinition only returns a location, and Hover does not accept a selection. So there's no way to ask the type of just the "f(x)" portion of f(x).y. We should lobby for LSP to add a selection to Hover.)