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: suggest go.mod go version update if generics code is found #51086

Closed
hyangah opened this issue Feb 8, 2022 · 4 comments
Closed
Labels
FrozenDueToAge 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

@hyangah
Copy link
Contributor

hyangah commented Feb 8, 2022

gopls version

Build info
----------
golang.org/x/tools/gopls v0.8.0-pre.1
    golang.org/x/tools/gopls@v0.8.0-pre.1 h1:6iHi9bCJ8XndQtBEFFG/DX+eTJrf2lKFv4GI3zLeDOo=
    github.com/BurntSushi/toml@v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
    github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
    golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/tools@v0.1.10-0.20220208182953-aa67a3805780 h1:dJUO1mSHzlsDAMryXy1rbUUZPt/lSvVdbYAd9oeRqwo=
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/tools@v0.2.2 h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk=
    mvdan.cc/gofumpt@v0.2.1 h1:7jakRGkQcLAJdT+C8Bwc9d0BANkVPSkHZkzNv07pJAs=
    mvdan.cc/xurls/v2@v2.3.0 h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I=
go: go1.18beta2

go version

go version go1.18beta2 darwin/amd64

What did you do?

copy/pasted generics code but forgot to update go.mod go version (and kept go1.17)

What did you expect to see?

Message indicating go.mod needs update.

What did you see instead?

Screen Shot 2022-02-08 at 4 56 28 PM

Message that I need go1.18. That's true, but can be confusing for some users.

Quickfix that updates go.mod version string will be a big plus!

Logs

Gopls is correctly using go1.18beta2.

[Info  - 4:36:44 PM] 2022/02/08 16:36:44 go env for /Users/hakim/tt
(root /Users/hakim/tt)
(go version go version go1.18beta2 darwin/amd64)
(valid build configuration = true)
(build flags: [])
GO111MODULE=
GOMOD=/Users/hakim/tt/go.mod
...
GOROOT=/Users/hakim/sdk/go1.18beta2
@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 Feb 8, 2022
@gopherbot gopherbot added this to the Unreleased milestone Feb 8, 2022
@findleyr
Copy link
Contributor

findleyr commented Feb 8, 2022

I agree!

For context, the types2 error message directly suggests checking go.mod, but go/types doesn't, because we probably don't want to couple go/types to a build system.

But we can recognize the error code, extract the go version regexp from the error message, find the relevant go.mod file, and offer a quickfix to do the mod edit.

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.8.0 Feb 11, 2022
@suzmue suzmue modified the milestones: gopls/v0.8.0, gopls/v0.8.1 Feb 11, 2022
@gopherbot
Copy link

Change https://go.dev/cl/386875 mentions this issue: internal/lsp: add quick fix for unsupported feature

gopherbot pushed a commit to golang/tools that referenced this issue Feb 28, 2022
Adds a command to run go mod edit -go to allow
users to easily upgrade their go directive.

Doing this change also revealed that changing
the go directive does not invalidate the type check
data and there may be stale diagnostics for a package.

Updates golang/go#51086

Change-Id: I659a216059c489a88e29cd51b944c3a0274f3700
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386875
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@findleyr
Copy link
Contributor

findleyr commented Mar 7, 2022

@suzmue is there anything left to do here?

@gopherbot
Copy link

Change https://go.dev/cl/390615 mentions this issue: internal/lsp: use regexp to add go mod edit -go quick fix

@golang golang locked and limited conversation to collaborators Mar 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

4 participants