Visual Studio Code调试代码与使用Golang的GoPath不匹配。

huangapple go评论115阅读模式
英文:

visual studio code debug code does not match gopath using golang

问题

Visual Studio Code使用Golang调试器与gopath路径代码不匹配?

我在Visual Studio Code IDE(MAC OS)上构建了Golang环境,然后安装了必要的工具:

  1. go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv
  2. go get -u -v github.com/nsf/gocode
  3. go get -u -v github.com/rogpeppe/godef
  4. go get -u -v github.com/golang/lint/golint
  5. go get -u -v github.com/lukehoban/go-find-references
  6. go get -u -v github.com/lukehoban/go-outline
  7. go get -u -v sourcegraph.com/sqs/goreturns
  8. go get -u -v golang.org/x/tools/cmd/gorename
  9. go get -u -v github.com/tpng/gopkgs
  10. go get -u -v github.com/newhook/go-symbols

我之前设置了我的gopath为/Users/friends/gopath,不久前我将我的gopath更改为/Users/friends/Document/share/gopath。我在**~/.bash_profileVisual Studio Code设置**中更改了gopath为:

  1. "go.gopath": "/Users/friends/Documents/VirtualMachine/share/gopath"

当我调试我的代码时,它提示找不到文件/Users/friends/gopath/src/...../apiSGetChainsIds.go,实际上该文件存在于/Users/friends/Documents/VirtualMachine/share/gopath/src/..../apiSGetChainsIds.go。显然,调试器找到了先前的gopath路径,这是Golang工具的错误吗?还是我做错了什么?

我的用户设置是:

  1. {
  2. "files.autoSave": "afterDelay",
  3. "go.buildFlags": [],
  4. "go.lintFlags": [],
  5. "go.vetFlags": [],
  6. "go.useCodeSnippetsOnFunctionSuggest": false,
  7. "go.formatOnSave": false,
  8. "go.formatTool": "goreturns",
  9. "editor.fontSize": 14,
  10. "go.goroot": "/usr/local/Cellar/go/1.8.3/libexec",
  11. "go.gopath": "/Users/friends/Documents/VirtualMachine/share/gopath"
  12. }
英文:

visual studio code using golang debugger does not match the gopath path code ?

I construct up golang environment using visual studio code IDE MAC OS, then install the necessary tools:

  1. go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv
  2. go get -u -v github.com/nsf/gocode
  3. go get -u -v github.com/rogpeppe/godef
  4. go get -u -v github.com/golang/lint/golint
  5. go get -u -v github.com/lukehoban/go-find-references
  6. go get -u -v github.com/lukehoban/go-outline
  7. go get -u -v sourcegraph.com/sqs/goreturns
  8. go get -u -v golang.org/x/tools/cmd/gorename
  9. go get -u -v github.com/tpng/gopkgs
  10. go get -u -v github.com/newhook/go-symbols

I ever set my go path /Users/friends/gopath , before long I changed my gopath /Users/friends/Document/share/gopath. I changed the gopath ~/.bash_profile ,visual studio code setting about

go.gopath": "/Users/friends/Documents/VirtualMachine/share/gopath

when I debug my code, it tips that can't find the file in/Users/friends/gopath/src/...../apiSGetChainsIds.go , actually the file exist in /Users/friends/Documents/VirtualMachine/share/gopath/src/..../apiSGetChainsIds.go .It is obvious that the debugger find the previous gopath ,is it the golang tools bug? or something I wrong?

my usersetting is

  1. {
  2. "files.autoSave": "afterDelay",
  3. //"go.buildOnSave": "package",
  4. //"go.lintOnSave": "package",
  5. //"go.vetOnSave": "package",
  6. "go.buildFlags": [],
  7. "go.lintFlags": [],
  8. "go.vetFlags": [],
  9. "go.useCodeSnippetsOnFunctionSuggest": false,
  10. "go.formatOnSave": false,
  11. "go.formatTool": "goreturns",
  12. "editor.fontSize": 14,
  13. "go.goroot": "/usr/local/Cellar/go/1.8.3/libexec",
  14. "go.gopath": "/Users/friends/Documents/VirtualMachine/share/gopath"
  15. }

答案1

得分: 1

我今天也遇到了运行它的问题,以下是必要的步骤:

  1. 获取 delve(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) 或者尝试使用 brew 安装。

  2. 在 launch.json 中添加一个启动配置,我的配置如下:

    1. "configurations": [
    2. {
    3. "name": "Launch Package",
    4. "type": "go",
    5. "request": "launch",
    6. "mode": "debug",
    7. "program": "${workspaceRoot}/myAppPackagePath/",
    8. "cwd": "${workspaceRoot}",
    9. "args": ["option1", "option2", "..."],
    10. "showLog": true
    11. }
    12. ]
英文:

I had also the problem to get it to run today, and here is what was necessary:

  1. get your self delve (https://github.com/derekparker/delve)

either a) if you prefer to build and install it, clone the repo to

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

and then run:

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

because of latest macOS security updates, you need also to code sign it:

  1. codesign -s dlv-cert $(which dlv)

or b) try brew

  1. add a launch configuration into launch.json, my working looked as follows:

"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}/myAppPackagePath/",
"cwd": "${workspaceRoot}",
"args": ["option1","option2","..."],
"showLog": true
}
]

huangapple
  • 本文由 发表于 2017年9月8日 10:33:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/46107769.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定