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: packages.Load failure with conflicting go.work and go.mod toolchain versions #69646

Open
remko-bw opened this issue Sep 16, 2024 · 2 comments
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

@remko-bw
Copy link

remko-bw commented Sep 16, 2024

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.7 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.16.2
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.93.1
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.42.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.


## Environment

GOBIN: undefined
toolsGopath: 
gopath: /Users/remko/.go
GOROOT: /Users/remko/.go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.7.darwin-arm64
PATH: ...

## Tools

	go:	/opt/homebrew/bin/go: go version go1.22.7 darwin/arm64

	gopls:	/Users/remko/.go/bin/gopls	(version: v0.16.2 built with go: go1.22.7)
	gotests:	/Users/remko/.go/bin/gotests	(version: v1.6.0 built with go: go1.22.7)
	gomodifytags:	/Users/remko/.go/bin/gomodifytags	(version: v1.17.0 built with go: go1.22.7)
	impl:	/Users/remko/.go/bin/impl	(version: v1.4.0 built with go: go1.22.7)
	goplay:	/Users/remko/.go/bin/goplay	(version: v1.0.0 built with go: go1.22.7)
	dlv:	/Users/remko/.go/bin/dlv	(version: v1.23.0 built with go: go1.22.7)
	staticcheck:	/Users/remko/.go/bin/staticcheck	(version: v0.5.1 built with go: go1.22.7)

## Go env

Workspace Folder (bw): /Users/remko/bw/bw

	GO111MODULE=''
	GOARCH='arm64'
	GOBIN=''
	GOCACHE='/Users/remko/Library/Caches/go-build'
	GOENV='/Users/remko/Library/Application Support/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFLAGS=''
	GOHOSTARCH='arm64'
	GOHOSTOS='darwin'
	GOINSECURE=''
	GOMODCACHE='/Users/remko/.go/pkg/mod'
	GONOPROXY=''
	GONOSUMDB=''
	GOOS='darwin'
	GOPATH='/Users/remko/.go'
	GOPRIVATE=''
	GOPROXY='https://proxy.golang.org,direct'
	GOROOT='/Users/remko/.go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.7.darwin-arm64'
	GOSUMDB='sum.golang.org'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/Users/remko/.go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.7.darwin-arm64/pkg/tool/darwin_arm64'
	GOVCS=''
	GOVERSION='go1.22.7'
	GCCGO='gccgo'
	AR='ar'
	CC='clang'
	CXX='clang++'
	CGO_ENABLED='1'
	GOMOD='/dev/null'
	GOWORK='/Users/remko/bw/bw/go.work'
	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/06/t4s5klwd24g25jxxgzbh6gwc0000gn/T/go-build439318135=/tmp/go-build -gno-record-gcc-switches -fno-common'

Share the Go related settings you have added/edited

  "go.lintTool": "staticcheck",
  "go.lintOnSave": "package",
  "go.vetOnSave": "package",
  "go.formatTool": "gofmt",
  "go.testFlags": ["-short"],
  "go.testEnvVars": {
    "NO_COLOR": "1"
  },
  "go.useLanguageServer": true,

Describe the bug

IntelliSense seems to be using the incorrect version of Go. I get the following error:

Screenshot 2024-09-16 at 10 47 56

I upgraded all my tools, and as you can see from the logs above, there is no mention of 1.22.5 anywhere.
Still, I get the following in my gopls log:

Screenshot 2024-09-16 at 10 34 36

Note that the version of go installed in in the PATH (/opt/homebrew/bin) is 1.22.5, but as far as I understand (and as the output of go version seem to confirm), it should use the 1.22.7 toolchain if that is what is requested by go.work.

@hyangah
Copy link
Contributor

hyangah commented Sep 17, 2024

Here is a minimal repro (system go version = go1.22.6)

-- go.work --
go 1.22.7

use (
        ./w1
        ./w2
)

-- w1/go.mod --
module w1

go 1.22.6

-- w2/go.mod --
module w2

go 1.22.6

[Info  - 12:49:12 PM] 2024/09/17 12:49:12 Created View (#1)
	directory=/Users/hakim/x
	view_type="GoWork"
	root_dir="file:///Users/hakim/x"
	go_version="go version go1.22.7 darwin/amd64"
	build_flags=[]
	env={GOOS:darwin GOARCH:amd64 GOCACHE:/Users/hakim/Library/Caches/go-build GOMODCACHE:/Users/hakim/go/pkg/mod GOPATH:/Users/hakim/go GOPRIVATE: GOFLAGS: GO111MODULE: GOTOOLCHAIN:auto GoVersion:22 GoVersionOutput:go version go1.22.7 darwin/amd64
 ExplicitGOWORK: EffectiveGOPACKAGESDRIVER:}
	env_overlay=[]

[Info  - 12:49:12 PM] 2024/09/17 12:49:12 16.579128ms for GOROOT= GOPATH=/Users/hakim/go GO111MODULE=auto GOPROXY=https://proxy.golang.org,direct PWD=/Users/hakim/x go list -f "{{context.GOARCH}} {{context.Compiler}}" -- unsafe

[Trace - 12:49:12.617 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2024/09/17 12:49:12 15.750208ms for GOROOT= GOPATH=/Users/hakim/go GO111MODULE=auto GOPROXY=https://proxy.golang.org,direct PWD=/Users/hakim/x go list -e -json=Name,ImportPath,Error,Dir,GoFiles,IgnoredGoFiles,IgnoredOtherFiles,CFiles,CgoFiles,CXXFiles,MFiles,HFiles,FFiles,SFiles,SwigFiles,SwigCXXFiles,SysoFiles,TestGoFiles,XTestGoFiles,CompiledGoFiles,Export,DepOnly,Imports,ImportMap,TestImports,XTestImports,ForTest,DepsErrors,Module,EmbedFiles -compiled=true -test=true -export=false -deps=true -find=false -pgo=off -- /Users/hakim/x/w1/... /Users/hakim/x/w2/... builtin\n"}


[Trace - 12:49:12.617 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2024/09/17 12:49:12 go/packages.Load golang/vscode-go#1: err: exit status 1: stderr: go: go.work requires go \u003e= 1.22.7 (running go 1.22.6)\n\n\tview_id=\"1\"\n\tsnapshot=0\n\tdirectory=/Users/hakim/x\n\tquery=[/Users/hakim/x/w1/... /Users/hakim/x/w2/... builtin]\n\tpackages=0\n\tduration=30.288576ms\n"}

I enabled verbose logging, but nothing obvious in the log. I tried to run the shown go list commands and they seem to work(?) without errors.

@findleyr
Copy link
Member

Thanks for this issue. This sounds like a gopls bug, so I'll transfer to the next gopls milestone.

@findleyr findleyr changed the title packages.Load error x/tools/gopls: packages.Load failure with conflicting go.work and go.mod toolchain versions Sep 26, 2024
@findleyr findleyr transferred this issue from golang/vscode-go Sep 26, 2024
@findleyr findleyr added this to the gopls/v0.17.0 milestone Sep 26, 2024
@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 Sep 26, 2024
@findleyr findleyr modified the milestones: gopls/v0.17.0, gopls/v0.18.0 Nov 5, 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

4 participants