golang / vscode-go

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

Error loading workspace in single .mod files repos #2347

Closed morawskiOZ closed 2 years ago

morawskiOZ commented 2 years 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.18.4 linux/amd64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. - Build info golang.org/x/tools/gopls v0.9.1 golang.org/x/tools/gopls@v0.9.1 h1:SigsTL4Hpv3a6b/a7oPCLRv5QUeSM6PZNdta1oKY4B0= 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/exp/typeparams@v0.0.0-20220218215828-6cf2b201936e h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM= golang.org/x/mod@v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/tools@v0.1.12-0.20220713141851-7464a5a40219 h1:Ljlba2fVWOA1049JjsKii44g8nZN2GjpxMlzVc8AnQM= golang.org/x/vuln@v0.0.0-20220613164644-4eb5ba49563c h1:r5bbIROBQtRRgoutV8Q3sFY58VzHW6jMBYl48ANSyS4= honnef.co/go/tools@v0.3.2 h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34= mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4= mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc= go: go1.18.4 * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - 1.69.1 b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a x64 * Check your installed extensions to get the version of the VS Code Go extension - v0.34.1 * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. - Checking configured tools.... GOBIN: undefined toolsGopath: gopath: /home/pm/go GOROOT: /usr/local/go PATH: /home/pm/.nvm/versions/node/v18.4.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/local/go/bin:/home/pm/go/bin:/usr/local/go/bin:/home/pm/go/bin go: /usr/local/go/bin/go: go version go1.18.4 linux/amd64 gotests: /home/pm/go/bin/gotests (version: v1.6.0 built with go: go1.18.4) gomodifytags: /home/pm/go/bin/gomodifytags (version: v1.16.0 built with go: go1.18.4) impl: /home/pm/go/bin/impl (version: v1.1.0 built with go: go1.18.4) goplay: /home/pm/go/bin/goplay (version: v1.0.0 built with go: go1.18.4) dlv: /home/pm/go/bin/dlv (version: v1.9.0 built with go: go1.18.4) golint: /home/pm/go/bin/golint (version: v0.0.0-20210508222113-6edffad5e616 built with go: go1.18.4) gopls: /home/pm/go/bin/gopls (version: v0.9.1 built with go: go1.18.4) go env Workspace Folder (binance-monitor): /home/pm/code/Github/binance-monitor GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/pm/.cache/go-build" GOENV="/home/pm/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/pm/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/pm/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18.4" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/pm/code/Github/binance-monitor/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build507315581=/tmp/go-build -gno-record-gcc-switches"

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.

  "[go]": {
    "editor.defaultFormatter": "golang.go",
  },
  "go.formatTool": "goimports",
  "go.autocompleteUnimportedPackages": true,
  "go.toolsManagement.autoUpdate": true,
  "go.buildTags": "ignore",
  "go.lintTool": "golint",
  "gopls": {
    "ui.semanticTokens": true,
    "ui.navigation.importShortcut": "Definition"
  },

Describe the bug

After bumping go ver to 1.18.4 all my repos show this error: Error loading workspace: err: exit status 1: stderr: go build syscall: package using cgo has Go assembly file asm_linux_amd64.s go build runtime: package using cgo has Go assembly file asm.s : packages.Load error

I 've updated every tool and pck I could but still no luck. I don't run multi packages repos so I am suprised I get workspace error.

Steps to reproduce the behavior:

Pretty sure it is only my setup problems (maybe some envs)

Screenshots or recordings

image

jamalc commented 2 years ago

Does the project compile with the updated go tool chain (i.e. from the workspace root directory, run go clean; go build -tags=ignore ./...)? Also, try reinstalling the go toolchain (make sure the GOROOT of the previous version was completely deleted and reinstall).

morawskiOZ commented 2 years ago

Does the project compile with the updated go toolchain (i.e. from the workspace root directory, run go clean; go build -tags=ignore ./...)? Also, try reinstalling the go toolchain (make sure the GOROOT of the previous version was completely deleted and reinstall).

@jamalc I reinstalled go again following the official docs, still the same error.

When I try to compile from project root with go clean; go build -tags=ignore ./... I am getting multiple imports x import cycle not allowed for all packages (strange) image

If I run go build inside my cmd folder, it builds binary just fine.

hyangah commented 2 years ago

@morawskiOZ Do you encounter the problem if you remove the "go.buildTags" setting? I understand why you want it but it seems like gopls is currently not capable of handling the conflicts caused by adding ignore-ed files in the runtime, syscall and many other packages. I am not quite sure about the original issue (syscall: package using cgo has Go assembly file asm_linux_amd64.s error message but it's possible that that is a side-effect of including files that are supposed to be ignored.

There are multiple open issues in gopls related to better build tag supports

morawskiOZ commented 2 years ago

@morawskiOZ Do you encounter the problem if you remove the "go.buildTags" setting? I understand why you want it but it seems like gopls is currently not capable of handling the conflicts caused by adding ignore-ed files in the runtime, syscall and many other packages. I am not quite sure about the original issue (syscall: package using cgo has Go assembly file asm_linux_amd64.s error message but it's possible that that is a side-effect of including files that are supposed to be ignored.

There are multiple open issues in gopls related to better build tag supports

Yes, that was it. Thank you @hyangah and @jamalc for all the help. Super weird that this showed up only after I bumped Go and all the tools to the newest version. Anyway, as there are already gopls related issues open I am closing this one. I hope this issue will help some poor soul in the future with the same problem ;)