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: warn about standard library API usage based on Go version #50689

Open
findleyr opened this issue Jan 19, 2022 · 2 comments
Open

x/tools/gopls: warn about standard library API usage based on Go version #50689

findleyr opened this issue Jan 19, 2022 · 2 comments
Labels
gopls Tools

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented Jan 19, 2022

With 1.18 (which adds types.Config.GoVersion), we'd like to better support a workflow that uses gopls built at a recent version of Go to develop projects that target running at an older version of Go.

#50688 is necessary but not sufficient: setting types.Config.GoVersion will not catch usage of standard library APIs that were added in later Go versions. We need to add additional diagnostics to gopls.

The right way to do this is probably via an analyzer that has a flag configuring its target language version. This makes it easier for users to eventually leverage this functionality outside of gopls, or turn it of/on within gopls.

High level idea:

  • Add a new analyzer (initially in x/tools/internal/lsp/analysis) that reports usage of standard library APIs that do not exist at a target language version. It can read from GOROOT/api to build the list of accepted APIs.
  • Either infer the target language version for a package from go.mod, or (more likely) expose a setting to configure it. Unlike for types.Config.GoVersion, reading go.mod is probably not good enough here, because IIRC the Go command does not enforce restrictions on standard library API use, so we would disagree. Perhaps we should not have a gopls`-specific configuration option, but rather expose a more general pattern for configuring analyzer flags.
@findleyr findleyr added this to the gopls/v0.8.0 milestone Jan 19, 2022
@bcmills
Copy link
Member

@bcmills bcmills commented Jan 19, 2022

Compare #46136, which proposes a similar warning for cmd/vet.

@gopherbot gopherbot added Tools gopls labels Jan 19, 2022
@findleyr findleyr removed this from the gopls/v0.8.0 milestone Feb 17, 2022
@findleyr findleyr added this to the gopls/v0.8.1 milestone Feb 17, 2022
@findleyr findleyr removed this from the gopls/v0.8.1 milestone Mar 7, 2022
@findleyr findleyr added this to the gopls/v0.8.2 milestone Mar 7, 2022
@findleyr findleyr removed this from the gopls/v0.8.2 milestone Mar 22, 2022
@findleyr findleyr added this to the gopls/on-deck milestone Mar 22, 2022
@findleyr
Copy link
Contributor Author

@findleyr findleyr commented May 17, 2022

I think we don't need to do this. The correct solution is to use the correct version go command.

Moving to our unplanned milestone.

@findleyr findleyr removed this from the gopls/later milestone May 17, 2022
@findleyr findleyr added this to the gopls/unplanned milestone May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Tools
Projects
None yet
Development

No branches or pull requests

3 participants