Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: typeDefinition: support more kinds of syntax #67890

Open
adonovan opened this issue Jun 7, 2024 · 2 comments
Open

x/tools/gopls: typeDefinition: support more kinds of syntax #67890

adonovan opened this issue Jun 7, 2024 · 2 comments
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Jun 7, 2024

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.)

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jun 7, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jun 7, 2024
@adonovan adonovan changed the title x/tools/gopls: typeDefinitioon x/tools/gopls: typeDefinition: support more kinds of syntax Jun 7, 2024
@suzmue suzmue modified the milestones: Unreleased, gopls/backlog Jun 11, 2024
@vikblom
Copy link

vikblom commented Jun 28, 2024

Hi, I'd be interested in helping out with this, although I am a bit fuzzy on what should be added.

As far as I know I only use typeDefinition as a goto/jump.

Playing around with gopls v0.16.0 it seems like struct fields (in definitions, assignment, and access) can be "jumped from". Is there a case I'm missing?

The same goes for an expression like

s.view.importsState.runProcessEnvFunc(ctx, s, fn)

where the snapshot, view and importState types can all be reached. Although the type of the function return, which is error, does not work, so perhaps that is a good place to start?

@findleyr
Copy link
Contributor

@vikblom indeed, struct fields do work. I think that decreases the utility of this issue significantly; jumping to the type definition of call expressions can be achieved by jumping on the function name, since it traverses through the structure of simple expressions to find the "element" type.

Perhaps https://go.dev/issue/66557, which you've already identified, is a better place for a next contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants