visual studio code debug code does not match gopath using golang

2k views Asked by At

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

There are 1 answers

1
Macilias On

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 } ]