Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Cursor "debug test" is not picking up GOPATH from launch.json #1057

Closed
beforeisleep opened this issue Jun 27, 2017 · 19 comments · Fixed by #1065
Closed

Cursor "debug test" is not picking up GOPATH from launch.json #1057

beforeisleep opened this issue Jun 27, 2017 · 19 comments · Fixed by #1065

Comments

@beforeisleep
Copy link

This is the menu that displays when mouse hovers over test functions. It worked before recent VS Code update.

VS Code: 1.13.1
vscode-go: 0.6.62
Go: go1.8.1 darwin/amd64

@ramya-rao-a
Copy link
Contributor

Can you run the command Go: Current GOPATH and tell me if what you see there is the same GOPATH that you have set in launch.json?

@beforeisleep
Copy link
Author

It shows the correct GOPATH that is set in launch.json. It is also the same GOPATH in the workspace settings.

I have no problems in running or debugging the program normally. This issue is only with the cursor "debug test" menu. Thank you for looking into this.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jun 28, 2017

What error do you see? Is it about dlv not being found?

@beforeisleep
Copy link
Author

It fails because it cannot find dependencies. The "(from $GOROOT)" line in the error trace is pointing to a different directory.

@ramya-rao-a
Copy link
Contributor

The error trace would have a line for $GOROOT and another for $GOPATH
Which of the 2 is wrong?

@beforeisleep
Copy link
Author

$GOPATH, not $GOROOT

@beforeisleep
Copy link
Author

The $GOPATH in the error trace seems to point to $HOME/go/src.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jun 30, 2017

$HOME/go/src looks like the default GOPATH in Go 1.8
And the GOPATH you get when running the Go: Current GOPATH is different?

@goenning This feels like it is related to
https://github.com/Microsoft/vscode-go/pull/971/files/3ac188357a53c44822129925a91ddfa64f65284b#diff-ce8c83cf87f491c0ab381e163db9daf4

Can you take a look?

I am leaving for a week long vacation without access to my Mac and so won't be able to get to the bottom of this

@beforeisleep Thanks for your patience

@goenning
Copy link
Contributor

goenning commented Jun 30, 2017

Hi, let me see if I can help.

"debug test" doesn't load anything from launch.json as there could be multiple configurations and we wouldn't know which one to use.

The current environment variables that are used during "debug test" are:

  1. System Environment Variables
  2. go.testEnvVars from settings.json file
  3. go.testEnvFile from settings.json file

@beforeisleep can you add this to your settings.json file just to confirm my hypothesis.

"go.testEnvVars": {
  "GOPATH": "<your gopath>"
},

If it does work, then @ramya-rao-a is right and my commit messed up with this. The go.gopath setting is only loaded by the Go Plugin process and not delve (which is ran in another process). This would explain why Ramya was passing the GOPATH to Delve.

@beforeisleep
Copy link
Author

The suggested change in settings.json, in fact, makes this problem go away.

Thanks for looking into this.

@goenning
Copy link
Contributor

goenning commented Jul 1, 2017

Thanks for the response. Stick with this workaround for now, I'll soon submit a PR.

@ramya-rao-a
Copy link
Contributor

The fix is now out in the latest update (0.6.63) to the Go extension
Thanks @goenning !

@bsr203
Copy link

bsr203 commented Oct 15, 2017

Hi @goenning , @ramya-rao-a

I have an issue related to above, so wanted to check quickly before opening a new one.

when I run the code lens "run test", I get the error

Running tool: /usr/local/go/bin/go test -tags appenginevm -timeout 30s aaa/bbb/ccc -run ^TestTasks$

can't load package: package aaa/bbb/ccc: build constraints exclude all Go files in /Users/bsr/server/src/aaa/bbb/ccc
Error: Tests failed.

It is indeed a GOPATH issue. It works if

  1. on vscode terminal
    GOPATH=/Users/bsr/server /usr/local/go/bin/go test -tags appenginevm -timeout 30s aaa/bbb/ccc -run ^TestTasks$

  2. If I open vscode with GOPATH set like
    GOPATH=/Users/bsr/server code
    then
    /usr/local/go/bin/go test -tags appenginevm -timeout 30s aaa/bbb/ccc -run ^TestTasks$

I have these settings on workspace level.

"go.gopath":
    "${workspaceRoot}:${workspaceRoot}/../external,
  "go.toolsGopath": "~/work/go/tools",
  "go.testEnvVars": {
    "GOPATH":
        "${workspaceRoot}:${workspaceRoot}/../external
  },
  "go.testFlags": ["-tags appenginevm"]

where
GOPATH = ${workspaceRoot}

can you please let me know testEnvVars or go.gopath is passed to code lens run test.

thanks.

@ramya-rao-a
Copy link
Contributor

@bsr203 The GOPATH from the go.gopath setting is used by the run test codelens. You shouldn't have to add it again via the go.testEnvVars setting.

In you second case above where you set GOPATH in the terminal and then open code, does the run test codelens work as expected? In that case do you still use the same settings?

@bsr203
Copy link

bsr203 commented Oct 16, 2017

thanks @ramya-rao-a for getting back to me.

No. run test through code lens doesn't work and gives the error can't load package as above. Means GOPATH is not set. But, the command it runs, as per the error message /usr/local/go/bin/go test -tags appenginevm -timeout 30s aaa/bbb/ccc -run ^TestTasks$, works on the vscode tesrminal (without me setting GOPATH). So, GOPATH is not passed when running through code lens. Go: Current GOPATH shows the correct GOPATH value.

@bsr203
Copy link

bsr203 commented Oct 16, 2017

hi. not sure what changed. after removing go.testEnvVars it detects GOPATH. I don't have errors about PATH anymore. I still have issues that build flag is not working properly. As in the above error the command has -tags appenginevm when run through code lens. But I am getting error that functions from that file is undefined. Do you see any issue how I use go.testEnvVar ?

@ramya-rao-a
Copy link
Contributor

Why not use the setting go.buildTags for the build tags?

@bsr203
Copy link

bsr203 commented Oct 16, 2017

@ramya-rao-a it works now. I have to use buildTags instead of testFlags.
like
"go.buildTags": "appenginevm"

@ramya-rao-a
Copy link
Contributor

great, Happy Coding!

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants