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

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

visual studio code debug code does not match gopath using golang

问题

Visual Studio Code使用Golang调试器与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。我在**~/.bash_profileVisual Studio Code设置**中更改了gopath为:

"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.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"
}
英文:

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:

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

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

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

答案1

得分: 1

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

  1. 获取 delve(https://github.com/derekparker/delve)

    a) 如果你喜欢构建和安装它,请克隆该仓库到 ~/go/src/github.com/derekparker/delve,然后运行:

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

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

    codesign -s dlv-cert $(which dlv)
    

    b) 或者尝试使用 brew 安装。

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

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

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

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

and then run:

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

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

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:

确定