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

"debug test" only work with one version of go? #3152

Closed
zhiqiangxu opened this issue Apr 5, 2020 · 2 comments · Fixed by #3159
Closed

"debug test" only work with one version of go? #3152

zhiqiangxu opened this issue Apr 5, 2020 · 2 comments · Fixed by #3159
Labels

Comments

@zhiqiangxu
Copy link

zhiqiangxu commented Apr 5, 2020

Describe the bug

I use gvm to manage multiple go versions:

$ gvm list

gvm gos (installed)

   go1.10
   go1.12
=> go1.13

I have two projects, one is configured to use go1.13:

  "go.gopath": "/Users/xuzhiqiang/.gvm/pkgsets/go1.13/global",
  "go.goroot": "/Users/xuzhiqiang/.gvm/gos/go1.13",

The other is configured to use go1.12:

  "go.gopath": "/Users/xuzhiqiang/.gvm/pkgsets/go1.12/global",
  "go.goroot": "/Users/xuzhiqiang/.gvm/gos/go1.12",

It seems to me that vscode will stick to the same go tool version for debug test, so the first project can run debug test successfully, but the second one will report go version does not match go tool version, like this:

# internal/nettrace
compile: version "go1.12" does not match go tool version "go1.13"
# github.com/oklog/run
compile: version "go1.12" does not match go tool version "go1.13"
# encoding
compile: version "go1.12" does not match go tool version "go1.13"

The root cause seems to be that vscode somehow doesn't choose the dlv under configured GOROOT ?

@hyangah
Copy link
Contributor

hyangah commented Apr 7, 2020

I think this is because the delve invokes the go command with just the executable name (go) (https://github.com/go-delve/delve/blob/master/pkg/gobuild/gobuild.go#L66) so picks up any go command found from the PATH.

As a workaround, try to add ${YOUR_GOROOT}/bin as the first PATH element. There are many ways to set this env var - one way is to use `"go.toolsEnvVar"'.

We can consider passing the "go.goroot"/bin when launching the debug adapter.
@ramya-rao-a @quoctruong @polinasok

I don't see any other way to teach delve about the path to the go binary yet.

hyangah added a commit to hyangah/vscode-go-old that referenced this issue Apr 7, 2020
Users can specify the go command to use by setting GOROOT env var,
`go.goroot` vscode setting, or PATH env var. getBinPath('go') is
used to choose the right version of 'go' whenever the extension
tries to invoke the go commands. However, this does not affect
other tools that invoke the go command underneath.

For example, delve, gopls, and many tools simply pick a version of
go from PATH. If the GOROOT env var and the version of go found in
the PATH don't match, this can lead to errors.

This CL places the go runtime base bin path as the first element of
the PATH env var. That ensures any tools invoked by the extension
to pick the same version of go, as long as they stick with the usual
PATH-based executable search.

Note this process.env mutation does not affect the environment variable
settings the integrated terminal would see, but this is not a new
problem.

Fixes microsoft#3152
ramya-rao-a pushed a commit that referenced this issue Apr 16, 2020
Users can specify the go command to use by setting GOROOT env var,
`go.goroot` vscode setting, or PATH env var. getBinPath('go') is
used to choose the right version of 'go' whenever the extension
tries to invoke the go commands. However, this does not affect
other tools that invoke the go command underneath.

For example, delve, gopls, and many tools simply pick a version of
go from PATH. If the GOROOT env var and the version of go found in
the PATH don't match, this can lead to errors.

This CL places the go runtime base bin path as the first element of
the PATH env var. That ensures any tools invoked by the extension
to pick the same version of go, as long as they stick with the usual
PATH-based executable search.

Note this process.env mutation does not affect the environment variable
settings the integrated terminal would see, but this is not a new
problem.

Fixes #3152
@ramya-rao-a
Copy link
Contributor

The latest update 0.14.2 has the fix for this, Thanks @hyangah

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

Successfully merging a pull request may close this issue.

4 participants