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 if language version is newer than compile version #68258

Open
findleyr opened this issue Jul 1, 2024 · 4 comments
Open
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@findleyr
Copy link
Contributor

findleyr commented Jul 1, 2024

As suggested by @matta in #68248, we should warn when the version of Go used to compile gopls is older than the language version implied by the go.mod file. A diagnostic on the go directive of the go.mod file probably suffices.

FWIW, I reported a similar issue in staticcheck. There, the fix to build with go1.23rc1 worked as well.

@dominikh also added code to staticcheck that will report an error if the tool is used on a go module requiring versions of go newer than what the tool was built with. gopls could consider a similar check.

Originally posted by @matta in #68248 (comment)

@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 Jul 1, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jul 1, 2024
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.17.0 Jul 1, 2024
@dominikh
Copy link
Member

dominikh commented Jul 1, 2024

Note that Staticcheck primarily has its own logic for this to produce better error messages. go/types already complains when the asked-for language version is newer than the version of go/types, but in Go 1.22, the error message read package requires newer Go version go1.23. Starting with Go 1.23, it seems to produce a better error message: /home/dominikh/prj/src/example.com/foo.go:3:1: package requires newer Go version go1.24 (application built with go1.23).

8121604 seems to be the commit that improved the message.

@matta
Copy link

matta commented Jul 1, 2024

Will a diagnostic in go.mod be enough? In my experience, "show all workspace diagnostics" is not consistently supported (or used) in editors. They show diagnostics only for the files the editor has opened.

In the case of #68248, I built with go1.23rc1 on the command line with go build ./... and saw all was well, then opened up a .go file in the project and saw the diagnostic from gopls. At that point, I did not open go.mod to check for additional diagnostics there.

In @dominikh's example above, maybe the error would appear for every file, which would cover it, I think.

@findleyr
Copy link
Contributor Author

This is much less of a problem now that gopls requires the latest Go version.
It's also hard to test (for the same reason!).

Bumping to the next release.

@findleyr findleyr modified the milestones: gopls/v0.17.0, gopls/v0.18.0 Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. 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