Closed spencerschrock closed 1 year ago
Could it be that gopls
is using a different Go version than expected?
I noticed that after upgrading a project to Go 1.21 and then running go mod tidy
, new go.sum entries were created. AFAIK there's no guarantee that go mod tidy
output is stable between Go releases. OTOH I also don't recall anything in the release notes that could hint at changes in this area.
@spencerschrock this might be the source of changes to go.sum
: https://go.dev/ref/mod#glos-go-mod-file:~:text=The%20go%20command%20is%20more%20careful%20about%20keeping%20checksums%20of%20go.mod%20files%20in%20the%20go.sum%20file.
(emphasis mine)
At go 1.21 or higher: The go line declares a required minimum version of Go to use with this module. The go line must be greater than or equal to the go line of all dependencies. The go command no longer attempts to maintain compatibility with the previous older version of Go. The go command is more careful about keeping checksums of go.mod files in the go.sum file.
Could it be that
gopls
is using a different Go version than expected?I noticed that after upgrading a project to Go 1.21 and then running
go mod tidy
, new go.sum entries were created. AFAIK there's no guarantee thatgo mod tidy
output is stable between Go releases. OTOH I also don't recall anything in the release notes that could hint at changes in this area.
I tried (locally) upgrading the project'sgo.mod
from 1.19 to 1.21, and go mod tidy
produces a different go.sum
, which I committed to my test branch. However upon reloading the project and viewing any Go file, entries are inserted again (which are removed after go mod tidy
).
If I leave the project at 1.19 and change my Go toolchain to 1.19 instead, the issue goes away. I tried a few more versions and the issue only starts when my Go toolchain is 1.20.5.
With that info, and the 1.20.5 milestone, I'm guessing it's this issue: https://github.com/golang/go/issues/60748
Thanks for investigating, @spencerschrock and @rhcarvalho.
Do you think there is anything to be improved here from the gopls side? We'd prefer to keep things simple, given that go.sum requirements will (eventually) stabilize.
I can follow #60748 for resolution. My only immediate thought is a local workaround, which will probably be me defining an alias for go mod tidy && git checkout
. Unless there's any hooks I can configure on the gopls side to run go mod tidy
for me.
Hmm, thinking about this a bit more, I'm not sure why gopls is fighting with you.
The only go commands gopls is running are go list
, go version
, and go env
. I don't think the Go command should be inserting sum lines that are removed on go mod tidy
. @bcmills does any of this ring bells? Is the behavior with go1.20.5+ perhaps inconsistent across operations?
FWIW, I'm skeptical that this is gopls at all. Looking at the log, no commands are being run, so go.sum shouldn't be changing regardless of any go command bugs. I suppose gopls could be buggy, but my money is on some linter or script doing it. Especially since I wasn't able to reproduce.
FWIW, I'm skeptical that this is gopls at all. Looking at the log, no commands are being run, so go.sum shouldn't be changing regardless of any go command bugs. I suppose gopls could be buggy, but my money is on some linter or script doing it.
The behavior went away when I turned off the language server(go.useLanguageServer
), or when I uninstalled gopls
, so I don't think it was script/linter related.
Especially since I wasn't able to reproduce.
Thanks for the data point. I requested a second cloud VM and was unable to reproduce there. After cleaning the modcache on my original VM, I was no longer able to reproduce there either. I'm not sure what state the modcache was in originally, but the issue is no longer occurring.
Apologies for the lack of go clean
troubleshooting earlier.
What did you do?
.go
fileWhat did you expect to see?
No changes to my
go.sum
file, as I haven't changed anything and the file was alreadygo mod tidy
'dWhat did you see instead?
125 insertions to
go.sum
that disappear when I rungo mod tidy
. Which is inconvenient when I try to change branches, as the uncommittedgo.sum
changes abort my checkout.Build info
Trace Output
Click to expand
Go/gopls extension settings
Occurs with default VS Code settings for Go and gopls