golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.78k stars 728 forks source link

gopls: panic with invalid Go version #3276

Closed wevertonrs closed 2 months ago

wevertonrs commented 3 months ago

gopls version: v0.15.2/go1.20.4 gopls flags: update flags: proxy extension version: 0.41.2 environment: Visual Studio Code win32 initialization error: undefined issue timestamp: Fri, 22 Mar 2024 22:38:21 GMT restart history: Fri, 22 Mar 2024 22:37:29 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: invalid Go version "go1.22.1" (should be something like "go1.12")

goroutine 624 [running]:
go/types.NewChecker(0x0%3F, 0xc0011400c0, 0xc0017ce7d0, 0x0%3F)
    C:/Program   check.go:237  0x24e
golang.org/x/tools/gopls/internal/cache.(*analysisNode).typeCheck(0xc000afa0b0, {0xc00000aa28, 0x1, 0x1})
      analysis.go:1028  0x73d
golang.org/x/tools/gopls/internal/cache.(*analysisNode).run(0xc000afa0b0, {0x1db9438%3F, 0xc00061d050})
      analysis.go:810  0x218
golang.org/x/tools/gopls/internal/cache.(*analysisNode).runCached(0xc000afa0b0, {0x1db9438%3F, 0xc00061d050})
      analysis.go:672  0x145
golang.org/x/tools/gopls/internal/cache.(*Snapshot).Analyze.func6.1()
      analysis.go:398  0xda
golang.org/x/sync/errgroup.(*Group).Go.func1()
      errgroup.go:78  0x64
created by golang.org/x/sync/errgroup.(*Group).Go
      errgroup.go:75  0xa5
gopls stats -anon { "DirStats": { "Files": 34, "TestdataFiles": 0, "GoFiles": 5, "ModFiles": 1, "Dirs": 20 }, "GOARCH": "amd64", "GOOS": "windows", "GOPACKAGESDRIVER": "", "GOPLSCACHE": "", "GoVersion": "go1.20.4", "GoplsVersion": "v0.15.2", "InitialWorkspaceLoadDuration": "4.0224353s", "MemStats": { "HeapAlloc": 8825880, "HeapInUse": 16572416, "TotalAlloc": 98190112 }, "WorkspaceStats": { "Files": { "Total": 493, "Largest": 210104, "Errs": 0 }, "Views": [ { "GoCommandVersion": "go1.22.1", "AllPackages": { "Packages": 67, "LargestPackage": 148, "CompiledGoFiles": 491, "Modules": 1 }, "WorkspacePackages": { "Packages": 5, "LargestPackage": 2, "CompiledGoFiles": 6, "Modules": 1 }, "Diagnostics": 0 } ] } }
OPTIONAL: If you would like to share more information, you can attach your complete gopls logs. NOTE: THESE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR CODEBASE. DO NOT SHARE LOGS IF YOU ARE WORKING IN A PRIVATE REPOSITORY.
suzmue commented 3 months ago

This was fixed in https://go.dev/cl/507975. To get this fix we recommend upgrading to go1.21 or later

Alfahan commented 3 months ago

Okey thanks!

tvendelin commented 3 months ago

The error message says

panic: invalid Go version "go1.22.1" (should be something like "go1.12")

but this IS the current version, according to https://go.dev/doc/install , isn't it? I've upgraded my Go today, and hitting this error every time I launch Neovim.

suzmue commented 3 months ago

Can you try reinstalling gopls with the newer go version? It appears to be built with go1.20.4. Running go install golang.org/x/tools/gopls@latest where go is go1.22.1 should reinstall with the newer toolchain.

After running you can verify that the go version is go1.22.1 by running the following:

$ gopls -v version

Please let me know if that works!

tvendelin commented 3 months ago

@suzmue : Indeed, after installing gopls explicitly, the issue is gone. A few things that were confusing to me:

Thank you, and sorry for confusion.