英文:
Can't debug Go in VSCode - cannot find GOROOT directory: /snap/bin/go
问题
我正在使用Ubuntu 20.04.3 LTS,VSCode 1.62.3和go 1.17.3 linux/amd64。
当我在VSCode中启动调试器时,它显示以下警告:
"dlv-dap"命令不可用。请选择"install",或按照此处的安装说明进行安装。来源:Go(扩展)[安装] [全部安装]
我点击安装并在输出中看到:
Tools environment: GOPATH=/home/raspberry/GolandProjects
在模块模式下在/home/raspberry/GolandProjects/bin中安装1个工具。
dlv-dap
安装github.com/go-delve/delve/cmd/dlv@master失败
{
"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个工具安装失败。
dlv-dap: 无法安装dlv-dap(github.com/go-delve/delve/cmd/dlv@master): 错误: 命令失败: /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.
英文:
I am using 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
> The "dlv-dap" command is not available. Please select "install", or
> follow the installation instructions here. Source: Go (Extension) [Install] [Install All]
I click Install and see that in the 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 env GOROOT
/usr/local/go
When I check /snap/bin/ I see that:
~$ 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. How to fix it?
UPDATE 1
When I set GOROOT to /snap/bin/go by typing this into the console:
$ export GOROOT=/snap/bin/go
VSCode starts to print that when I try to run the debugger:
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.
答案1
得分: 12
所以,这是修复方法-在VSCode中添加“首选项:打开设置(JSON)”这一行
"go.goroot": "/snap/go/current"
这是解释-https://github.com/golang/vscode-go/issues/166
英文:
So, here is the fix - add to VSCode Preferences: Open Settings (JSON)
this line
"go.goroot": "/snap/go/current"
Here is the explanation - https://github.com/golang/vscode-go/issues/166
答案2
得分: 0
以下是导航和添加的确切路径:
在VSCode中,转到
文件->首选项->设置->扩展->Go
您将找到"编辑为JSON"按钮。
在那个位置添加以下代码:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论