2

使用 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

我曾经设置/Users/friends/gopath过我的 gopath ,不久我改变了我的 gopath /Users/friends/Document/share/gopath。我更改了 gopath ~/.bash_profile,关于Visual Studio 代码设置

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工具的错误吗?还是我错了?

我的用户设置是

{
    "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"

    }
4

1 回答 1

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) 尝试冲泡

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

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

于 2018-01-19T15:21:07.503 回答