【问题标题】:visual studio code debug code does not match gopath using golangVisual Studio 代码调试代码与使用 golang 的 gopath 不匹配
【发布时间】: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_profilevisual 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 GOPATHView->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


【解决方案1】:

我今天也遇到了让它运行的问题,这是必要的:

  1. 进行自我探索 (https://github.com/derekparker/delve)

    a) 如果您更喜欢构建和安装它,请将 repo 克隆到

    ~/go/src/github.com/derekparker/delve

然后运行:

go install github.com/derekparker/delve/cmd/dlv

由于最新的 macOS 安全更新,您还需要对其进行代码签名:

codesign -s dlv-cert $(which dlv)

或 b) 尝试 brew

  1. 在launch.json中添加启动配置,我的工作如下:

“配置”:[ { "name": "启动包", “类型”:“去”, “请求”:“启动”, “模式”:“调试”, "程序": "${workspaceRoot}/myAppPackagePath/", "cwd": "${workspaceRoot}", "args": ["option1","option2","..."], “showLog”:真 } ]

【讨论】:

  • delve 未安装在 Windows 32 架构中。
猜你喜欢
  • 2015-08-04
  • 2012-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-30
  • 1970-01-01
  • 2011-10-11
  • 1970-01-01
相关资源
最近更新 更多