Skip to content

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

Closed
@adonovan

Description

@adonovan

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.

Activity

added
ToolsThis label describes issues relating to any tools in the x/tools repository.
goplsIssues related to the Go language server, gopls.
on May 3, 2024
added this to the Unreleased milestone on May 3, 2024
added
FeatureRequestIssues asking for a new feature that does not need a proposal.
and removed
ToolsThis label describes issues relating to any tools in the x/tools repository.
on May 3, 2024
adonovan

adonovan commented on May 3, 2024

@adonovan
MemberAuthor

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

changed the title [-]x/tools/gopls: make completion, hover use std version information[/-] [+]x/tools/gopls: make Hover display std version information[/+] on May 3, 2024
findleyr

findleyr commented on Jun 20, 2024

@findleyr
Member

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

adonovan commented on Jun 20, 2024

@adonovan
MemberAuthor

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

h9jiang commented on Jun 21, 2024

@h9jiang
Member

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

I will comment again for further questions.

gopherbot

gopherbot commented on Jun 25, 2024

@gopherbot
Contributor

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

gopherbot

gopherbot commented on Jun 26, 2024

@gopherbot
Contributor

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

gopherbot

gopherbot commented on Jun 27, 2024

@gopherbot
Contributor

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

gopherbot

gopherbot commented on Jul 1, 2024

@gopherbot
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FeatureRequestIssues asking for a new feature that does not need a proposal.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @adonovan@gopherbot@findleyr@h9jiang@hoeppi-google

      Issue actions

        x/tools/gopls: make Hover display std version information · Issue #67159 · golang/go