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: make Hover display std version information #67159

Closed
adonovan opened this issue May 3, 2024 · 8 comments
Closed

x/tools/gopls: make Hover display std version information #67159

adonovan opened this issue May 3, 2024 · 8 comments
Assignees
Labels
FeatureRequest gopls Issues related to the Go language server, gopls.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented May 3, 2024

While solving #46136 by adding a new analyzers, stdversion, we created an internal helper package https://pkg.go.dev/golang.org/x/tools/internal/stdlib that contains a manifest of all std symbols and their versions.
We should use this information in Completions, to ensure that only version-appropriate completions are offered;
and in Hover, to report the initial Go version for each std symbol. And perhaps other places as well.

@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 May 3, 2024
@gopherbot gopherbot added this to the Unreleased milestone May 3, 2024
@adonovan adonovan added FeatureRequest and removed Tools This label describes issues relating to any tools in the x/tools repository. labels May 3, 2024
@adonovan adonovan modified the milestones: Unreleased, gopls/v0.16.0 May 3, 2024
@adonovan
Copy link
Member Author

adonovan commented May 3, 2024

On closer inspection, apparently I already added version support to completion. So that leaves just Hover.

@adonovan adonovan changed the title x/tools/gopls: make completion, hover use std version information x/tools/gopls: make Hover display std version information May 3, 2024
@findleyr findleyr modified the milestones: gopls/v0.16.0, gopls/v0.17.0 May 23, 2024
@findleyr
Copy link
Contributor

A few rough ideas for how this could be implemented:

  • I think we should add an asOfVersion string field to hoverJSON. hoverJSON separates the data underlying hover from its presentation. The presentation format varies depending on client capabilities.
  • At the bottom of ./gopls/internal/golang.hover, where we have a non-nil obj (the types.Object describing the declaration), look up when the object was added to the standard library in ./internal/stdlib. Not sure exactly the best way to do this -- left as an exercise for the reader, but see existing usage of stdlib.PackageSymbols. In particular, Symbol.SplitField and Symbol.SplitMethod may be helpful for looking up fields and methods. We should perhaps have a helper to look up a types.Object.
  • If found, format the asOfVersion version as go1.X.
  • In at least the markdown presentation, insert an added in go1.X note somewhere. pkgsite provides an example for how users are accustomed to seeing this, e.g. https://pkg.go.dev/errors#As.
  • Add a new test file in ./gopls/internal/test/marker/testdata/hover exercising various standard library hover examples. In this file, we should exercise hover for at least (1) a symbol that has always existed in the standard library, (2) a symbol that was added to an existing package in a go version (such as errors.As), and (3) a symbol that was in the first version of a new package, such as slices.Contains.

CC @h9jiang @hyangah

@adonovan
Copy link
Member Author

We should perhaps have a helper to look up a types.Object.

While we're at it, we should use the same helper in the internal doc viewer (gopls/internal/golang/pkgdoc.go). This can be a separate CL.

@h9jiang
Copy link
Member

h9jiang commented Jun 21, 2024

Please assign to me to take a look. :D Thanks.

I will comment again for further questions.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/594875 mentions this issue: gopls/internal/server/hover: provide available version for std lib

gopherbot pushed a commit to golang/tools that referenced this issue Jun 26, 2024
Version is only available for the types of Var, Func, Const & Type.

For golang/go#67159

Change-Id: I77f95ccb6027914440ec7a2ea5338318c0f88e60
Reviewed-on: https://go-review.googlesource.com/c/tools/+/594875
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/595135 mentions this issue: gopls/internal/golang: provide version info for stdlib methods

gopherbot pushed a commit to golang/tools that referenced this issue Jun 27, 2024
For golang/go#67159

Change-Id: If3d09a39e8bf0a5ab61dc0953d7250ad75525372
Reviewed-on: https://go-review.googlesource.com/c/tools/+/595135
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/595336 mentions this issue: gopls/internal/golang: provide version info for stdlib fields

gopherbot pushed a commit to golang/tools that referenced this issue Jun 27, 2024
For golang/go#67159

Change-Id: I8b8b12949566857f29460675b9dc4d9c6804ff1e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/595336
Auto-Submit: Hongxiang Jiang <hxjiang@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/595855 mentions this issue: gopls/internal/golang: provide version info for stdlib in pkgdoc

gopherbot pushed a commit to golang/tools that referenced this issue Jul 2, 2024
The available versions are provided for functions and methods.
Same as https://pkg.go.dev/

1. The std lib version is only available for FUNC, METHOD, TYPE. Not
   available for CONST, VAR & FIELD. Because those types do not have
   dedicated HTML element, declarations are shown only as source code.
2. Introduce css element stdlibVersion which contains the styles needed.

For golang/go#67159

Change-Id: I4b4f469a858a1aca6598f2abed6f990ab1931b00
Reviewed-on: https://go-review.googlesource.com/c/tools/+/595855
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@h9jiang h9jiang closed this as completed Jul 2, 2024
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.
Projects
None yet
Development

No branches or pull requests

5 participants