使用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 /Users/friends/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工具的错误吗? 还是我错了?

我的用户设置是

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

  • 在launch.json中添加启动配置,我的工作如下所示:
  • "配置":[
    {
    " name":"启动包",
    " type":" go",
    " request":"启动",
    " mode":"调试",
    " program":" $ {workspaceRoot} / myAppPackagePath /",
    " cwd":" $ {workspaceRoot}",
    " args":[" option1"," option2"," ..."],
    " showLog":是
    }
    ]

    • delve不会安装在Windows 32体系结构中。