简体   繁体   English

无法在 VSCode 中调试 Go - 找不到 GOROOT 目录:/snap/bin/go

[英]Can't debug Go in VSCode - cannot find GOROOT directory: /snap/bin/go

I am using Ubuntu 20.04.3 LTS, VSCode 1.62.3, go 1.17.3 linux/amd64我正在使用 Ubuntu 20.04.3 LTS、VSCode 1.62.3、go 1.17.3 linux/amd64

When I start the debugger in VSCode it shows me this warning当我在 VSCode 中启动调试器时,它会向我显示此警告

The "dlv-dap" command is not available. “dlv-dap”命令不可用。 Please select "install", or follow the installation instructions here.请 select “安装”,或按照此处的安装说明进行操作。 Source: Go (Extension) [Install] [Install All]来源:Go(扩展)[安装] [全部安装]

I click Install and see that in the output:我单击安装并在 output 中看到:

Tools environment: GOPATH=/home/raspberry/GolandProjects
Installing 1 tool at /home/raspberry/GolandProjects/bin in module mode.
  dlv-dap

Installing github.com/go-delve/delve/cmd/dlv@master FAILED
{
 "killed": false,
 "code": 2,
 "signal": null,
 "cmd": "/usr/local/go/bin/go get -x -d github.com/go-delve/delve/cmd/dlv@master",
 "stdout": "",
 "stderr": "go: cannot find GOROOT directory: /snap/bin/go\n"
}

1 tools failed to install.

dlv-dap: failed to install dlv-dap(github.com/go-delve/delve/cmd/dlv@master): Error: Command failed: /usr/local/go/bin/go get -x -d github.com/go-delve/delve/cmd/dlv@master
go: cannot find GOROOT directory: /snap/bin/go

When I check GOROOT by the go tool I see that:当我通过 go 工具检查 GOROOT 时,我看到:

$ go env GOROOT
/usr/local/go

When I check /snap/bin/ I see that:当我检查 /snap/bin/ 时,我看到:

~$ cd /snap/bin/
:/snap/bin$ ls
canonical-livepatch  pre-commit.validate-config
go                   pre-commit.validate-manifest
gofmt                snap-store
go.gofmt             snap-store.ubuntu-software
pre-commit           snap-store.ubuntu-software-local-file

I'm confused, there is /snap/bin/go but VSCode tells me that there is not and fails to run the debugger.我很困惑,有 /snap/bin/go 但是 VSCode 告诉我没有并且无法运行调试器。 How to fix it?如何解决?

UPDATE 1更新 1

When I set GOROOT to /snap/bin/go by typing this into the console:当我通过在控制台中输入以下内容将 GOROOT 设置为 /snap/bin/go 时:

$ export GOROOT=/snap/bin/go

VSCode starts to print that when I try to run the debugger:当我尝试运行调试器时,VSCode 开始打印:

Couldn't find dlv-dap at the Go tools path, /home/raspberry/GolandProjects/, /home/raspberry/GolandProjects or /usr/local/go/bin:/home/raspberry/.local/bin:/home/raspberry/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Follow the setup instruction in https://github.com/golang/vscode-go/blob/master/docs/debugging.md#getting-started.

So, here is the fix - add to VSCode Preferences: Open Settings (JSON) this line所以,这里是修复 - 添加到 VSCode Preferences: Open Settings (JSON)这一行

"go.goroot": "/snap/go/current"

Here is the explanation - https://github.com/golang/vscode-go/issues/166这是解释 - https://github.com/golang/vscode-go/issues/166

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM