0

我正在使用 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.

4

1 回答 1

2

所以,这里是修复 - 添加到 VSCodePreferences: Open Settings (JSON)这一行

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

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

于 2021-12-04T07:51:32.753 回答