golang / vscode-go

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

VSCode plugin reports "Failed to run '/snap/bin/go env'", Go language features not working #3061

Closed hovinen closed 9 months ago

hovinen commented 9 months ago

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

$ go version
go version go1.21.4 linux/amd64
$ gopls -v version
Build info
----------
golang.org/x/tools/gopls (devel)
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/go-cmp@v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/mod@v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
    golang.org/x/sync@v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
    golang.org/x/sys@v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
    golang.org/x/telemetry@v0.0.0-20231011160506-788d5629a052 h1:1baVNneD/IRxmu8JQdBuki78zUqBtZxq8smZXQj0X2Y=
    golang.org/x/text@v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
    golang.org/x/tools@v0.14.1-0.20231026192422-8b5abd452b28 h1:5YgdZAe2w0x3Xrjv0+GXrI0jvm7qCQK/ySGFfiEHMfU=
    golang.org/x/vuln@v1.0.1 h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=
    honnef.co/go/tools@v0.4.5 h1:YGD4H+SuIOOqsyoLOpZDWcieM28W47/zRO7f+9V3nvo=
    mvdan.cc/gofumpt@v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.21.3
❯ code --version
1.84.2
1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
x64

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.

None found

Describe the bug

The Go plugin reports the error:

Failed to run '/snap/bin/go env' (cwd: <redacted>): Error: Command failed: /snap/bin/go env -json GOPATH GOROOT GOPROXY GOBIN GOMODCACHE

I can run the indicated command just fine in the terminal within VSCode:

$ /snap/bin/go env -json GOPATH GOROOT GOPROXY GOBIN GOMODCACHE
{
        "GOBIN": "",
        "GOMODCACHE": "/home/hovinen/go/pkg/mod",
        "GOPATH": "/home/hovinen/go",
        "GOPROXY": "https://proxy.golang.org,direct",
        "GOROOT": "/snap/go/10426"
}

The empty GOBIN is strange, but the plugin obviously able to find the binary.

None of the language features are working at all. All Go-related commands result in a modal indicating that the command was not found. No other error messages appear.

This is on a fresh install on Ubuntu 23.04 using Snaps for both VSCode and Go. I have tried uninstalling and reinstalling all relevant components to no effect.

Steps to reproduce the behavior:

  1. Install the go, vscode, and gopls snaps.
  2. Install the Go plugin in VSCode.
  3. Open any Go project.
  4. See the error in the output tab (screenshot attached).

2023-11-24 screenshot VSCode Go error

ansaba commented 9 months ago

cc: @hyangah

hyangah commented 9 months ago

Snap users need the following settings https://github.com/golang/vscode-go/issues/166#issuecomment-1516874141

"go.alternateTools": {
    "go": "/snap/go/current/bin/go"
}

to workaround the snap issue https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1849753

hovinen commented 9 months ago

Yep, that worked. Thank you!