【发布时间】:2017-09-08 02:33:38
【问题描述】:
使用 golang 调试器的 Visual Studio 代码与 gopath 路径代码不匹配?
我使用visual studio code IDE MAC OS搭建golang环境,然后安装必要的工具:
go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-find-references
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/newhook/go-symbols
我曾经设置过我的 gopath /Users/friends/gopath,不久之后我更改了我的 gopath /Users/friends/Document/share/gopath。我改了gopath ~/.bash_profile,visual studio code setting关于
go.gopath": "/Users/friends/Documents/VirtualMachine/share/gopath
调试代码时提示找不到/Users/friends/gopath/src/...../apiSGetChainsIds.go中的文件,实际上/Users/friends/Documents/VirtualMachine/share/gopath/src/..../apiSGetChainsIds.go中存在该文件。很明显调试器找到了之前的@987654328 @ ,是golang工具的bug吗?还是我错了?
我的用户设置是
{
"files.autoSave": "afterDelay",
//"go.buildOnSave": "package",
//"go.lintOnSave": "package",
//"go.vetOnSave": "package",
"go.buildFlags": [],
"go.lintFlags": [],
"go.vetFlags": [],
"go.useCodeSnippetsOnFunctionSuggest": false,
"go.formatOnSave": false,
"go.formatTool": "goreturns",
"editor.fontSize": 14,
"go.goroot": "/usr/local/Cellar/go/1.8.3/libexec",
"go.gopath": "/Users/friends/Documents/VirtualMachine/share/gopath"
}
【问题讨论】:
-
在
go.gopath值中,用实际目录替换波浪号前缀 (~),因为它是特定于 shell 的,可能不会被 vscode 替换。如果在.bash_profile中定义GOPATH,请使用GOPATH 而不是go.gopath。 -
对不起,其实我用的是绝对路径,不行。我已将我的问题描述 ~ 编辑为 /Users/friends
-
很明显,错误信息与
go.gopath的值完全不一样。通过菜单在 vscode 中验证 current GOPATH:View->Command Palette...->Go: Current GOPATH。还要查看vscode设置中go.inferGopath的值(默认为false,请使用默认值)。 -
通过菜单:View->Command Palette...->Go: Current GOPATH 是什么意思?我输入
go env,它显示GOPATH="/Users/friends/Documents/VirtualMachine/share/gopath",而go.inferGopath没有改变。 -
我的意思是,在您的 vscode IDE 中单击菜单
View,然后单击Command Palette...。我认为您的问题与https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code#cannot-find-package--in-any-of- 有关。
标签: go visual-studio-code delve