使用golang调试器的visual studio代码与gopath路径代码不匹配?
我使用Visual Studio代码IDE MAC OS搭建了golang环境,然后安装了必要的工具:
1 2 3 4 5 6 7 8 9 10 | 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 |
我曾经设置过go path
当我调试代码时,提示提示找不到
我的用户设置是
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | { "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 值中,将波浪号前缀(~ )替换为实际目录,因为它的特定于外壳程序,也许未由vscode替换。如果在.bash_profile 中定义GOPATH ,请使用GOPATH代替go.gopath 。 - 抱歉,实际上我使用的是绝对路径,它不能工作。我已经将我的问题描述修改为?/ Users / friends
-
显然,错误消息与
go.gopath 值并不完全相同。通过菜单View->Command Palette...->Go: Current GOPATH 验证vscode中的当前GOPATH。还要检查vscode设置中的go.inferGopath 值(默认值为false ,请使用默认值)。 -
通过菜单,您是什么意思:"视图"->"命令面板" ...->"转到:当前的GOPATH"?我输入
go env ,它显示GOPATH="UsersfriendsDocumentsVirtualMachinesharegopath" ,而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-有关。 -
命令面板显示
Current GOPATH: UsersfriendsDocumentsVirtualMachinesharegopath ,实际上在我的launch.json中,它写为`" env":{" CORE_LOGGING_LEVEL":" WARNING"," GOPATH":" / Users / friends / Documents / VirtualMachine / share / gopath"}, `
我还有一个问题要今天运行,这是必需的:
让你自我钻研(https://github.com/derekparker/delve)
a)如果您希望构建和安装它,请将存储库克隆到
?/ go / src / github.com / derekparker / delve
然后运行:
1 | go install github.com/derekparker/delve/cmd/dlv |
由于最新的macOS安全更新,您还需要对其进行代码签名:
1 | codesign -s dlv-cert $(which dlv) |
或b)尝试冲泡
"配置":[
{
" name":"启动包",
" type":" go",
" request":"启动",
" mode":"调试",
" program":" $ {workspaceRoot} / myAppPackagePath /",
" cwd":" $ {workspaceRoot}",
" args":[" option1"," option2"," ..."],
" showLog":是
}
]
- delve不会安装在Windows 32体系结构中。