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

Vscode not using correct Go version for tools #3305

Closed ybirader closed 3 months ago

ybirader commented 3 months ago

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
* Run `go version` to get version of Go from _the VS Code integrated terminal_. - go version go1.22.1 darwin/arm64 * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - 1.87.2 * Check your installed extensions to get the version of the VS Code Go extension - * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. ``` ## Environment GOBIN: undefined toolsGopath: gopath: /Users/yusufbirader/go/1.21.8 GOROOT: /Users/yusufbirader/go/1.21.8/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.1.darwin-arm64 ## Tools go: /Users/yusufbirader/.goenv/versions/1.21.8/bin/go: go version go1.22.1 darwin/arm64 gopls: /Users/yusufbirader/go/1.21.8/bin/gopls (version: v0.15.2 built with go: go1.21.8) gotests: /Users/yusufbirader/go/1.21.8/bin/gotests (version: v1.6.0 built with go: go1.21.8) gomodifytags: /Users/yusufbirader/go/1.21.8/bin/gomodifytags (version: v1.16.0 built with go: go1.21.8) impl: /Users/yusufbirader/go/1.21.8/bin/impl (version: v1.1.0 built with go: go1.21.8) goplay: /Users/yusufbirader/go/1.21.8/bin/goplay (version: v1.0.0 built with go: go1.21.8) dlv: /Users/yusufbirader/go/1.21.8/bin/dlv (version: v1.22.1 built with go: go1.21.8) staticcheck: /Users/yusufbirader/go/1.21.8/bin/staticcheck (version: v0.4.7 built with go: go1.21.8) ## Go env GO111MODULE='' GOARCH='arm64' GOBIN='' GOCACHE='/Users/yusufbirader/Library/Caches/go-build' GOENV='/Users/yusufbirader/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='boringcrypto' GOFLAGS='' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOINSECURE='' GOMODCACHE='/Users/yusufbirader/go/1.21.8/pkg/mod' GOOS='darwin' GOPATH='/Users/yusufbirader/go/1.21.8' GOPROXY='https://proxy.golang.org,direct' GOROOT='/Users/yusufbirader/go/1.21.8/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.1.darwin-arm64' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/Users/yusufbirader/go/1.21.8/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.1.darwin-arm64/pkg/tool/darwin_arm64' GOVCS='' GOVERSION='go1.22.1' GCCGO='gccgo' AR='ar' CC='clang' CXX='clang++' CGO_ENABLED='1' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/mw/hv9zss6532l6g9gcqqw2dckw0000gp/T/go-build1694814503=/tmp/go-build -gno-record-gcc-switches -fno-common' ``` ### Share the Go related settings you have added/edited Run `Preferences: Open Settings (JSON)` command to open your settings.json file. Share all the settings with the `go.` or `["go"]` or `gopls` prefixes. ### Describe the bug A clear and concise description of what the bug. A clear and concise description of what you expected to happen. I use `goenv` to manage go versions. As you can see, the go version being used is `1.22.1`. However, the go tools are configured for `1.21.8`. In my workspace, Intellisense does not work. I don't know how to ensure that vscode uses the correct version. When I run go env in the terminal, I get: ``` GO111MODULE='' GOARCH='arm64' GOBIN='' GOCACHE='/Users/yusufbirader/Library/Caches/go-build' GOENV='/Users/yusufbirader/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOINSECURE='' GOMODCACHE='/Users/yusufbirader/go/1.22.1/pkg/mod' GOOS='darwin' GOPATH='/Users/yusufbirader/go/1.22.1' GOPROXY='https://proxy.golang.org,direct' GOROOT='/Users/yusufbirader/.goenv/versions/1.22.1' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/Users/yusufbirader/.goenv/versions/1.22.1/pkg/tool/darwin_arm64' GOVCS='' GOVERSION='go1.22.1' GCCGO='gccgo' AR='ar' CC='clang' CXX='clang++' CGO_ENABLED='1' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/mw/hv9zss6532l6g9gcqqw2dckw0000gp/T/go-build1188911252=/tmp/go-build -gno-record-gcc-switches -fno-common' ``` which as you can see, is different from that show for the configured tools.