我正在使用 Ubuntu 20.04.3 LTS,VSCode 1.62.3,去 1.17.3 linux/amd64
当我在 VSCode 中启动调试器时,它会向我显示此警告
“dlv-dap”命令不可用。请选择“安装”,或按照此处的安装说明进行操作。来源:Go(扩展)[安装] [全部安装]
我单击安装并在输出中看到:
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
当我通过 go 工具检查 GOROOT 时,我看到:
$ go env GOROOT
/usr/local/go
当我检查 /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
我很困惑,有 /snap/bin/go 但是 VSCode 告诉我没有并且无法运行调试器。如何解决?
更新 1
当我通过在控制台中输入以下内容将 GOROOT 设置为 /snap/bin/go 时:
$ export GOROOT=/snap/bin/go
当我尝试运行调试器时,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.