Closed zhiqiangxu closed 3 years ago
@zhiqiangxu thanks for the report. What's the extension version? The extension should choose go
from /Users/xuzhiqiang/.gvm/gos/go1.15/bin
and "go.toolsEnvVars.PATH"
shouldn't affect the extension's choice of Go at all.
I am wildly guessing the extension passed a wrong PATH when invoking other tools.
Go: Locate Configured Go Tools
report without "go.toolsEnvVars"
setting?Sorry for late response!
module xxx
in go.mod
Checking configured tools....
GOBIN: undefined
toolsGopath:
gopath: /Users/xuzhiqiang/.gvm/pkgsets/go1.15/global
GOROOT: /Users/xuzhiqiang/.gvm/gos/go1.12
PATH: /Users/xuzhiqiang/.gvm/gos/go1.12/bin:/Users/xuzhiqiang/.wasmtime/bin:/Users/xuzhiqiang/.cargo/bin:/usr/local/opt/mysql-client/bin:/Users/xuzhiqiang/.gvm/pkgsets/go1.10/global/src/github.com/zhiqiangxu/client2/third_party/cocos2d-x/templates:/Users/xuzhiqiang/.gvm/pkgsets/go1.10/global/src/github.com/zhiqiangxu/client2/third_party:/Users/xuzhiqiang/.gvm/pkgsets/go1.10/global/src/github.com/zhiqiangxu/client2/third_party/cocos2d-x/tools/cocos2d-console/bin:/Users/xuzhiqiang/.cargo/bin:/Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin:/Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/overlay/bin:/Users/xuzhiqiang/.gvm/bin:/Users/xuzhiqiang/.gvm/bin:/Users/xuzhiqiang/.cargo/bin:/Users/xuzhiqiang/.rvm/gems/ruby-2.3.0/bin:/Users/xuzhiqiang/.rvm/gems/ruby-2.3.0@global/bin:/Users/xuzhiqiang/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/xuzhiqiang/.rvm/bin:/Users/xuzhiqiang/.rvm/bin:/Users/xuzhiqiang/.rvm/bin:/Users/xuzhiqiang/Downloads/flutter/bin:/Users/xuzhiqiang/Desktop/workspace/vagrant/java/build/apache-maven-3.5.0/bin/:/Users/xuzhiqiang/bin/:/usr/local/Cellar/protobuf/3.3.0/bin:/Users/xuzhiqiang/bin/dex2jar-2.1-SNAPSHOT:/Users/xuzhiqiang/Library/Android/sdk/platform-tools:/Users/xuzhiqiang/.luarocks/bin/:/Users/xuzhiqiang/Downloads/flutter/bin/cache/dart-sdk/bin
gocode: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gocode installed
gopkgs: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gopkgs installed
go-outline: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/go-outline installed
go-symbols: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/go-symbols installed
guru: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/guru installed
gorename: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gorename installed
gotests: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gotests installed
gomodifytags: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gomodifytags installed
impl: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/impl installed
fillstruct: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/fillstruct installed
goplay: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/goplay installed
godoctor: godoctor not installed
dlv: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/dlv installed
gocode-gomod: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gocode-gomod installed
godef: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/godef installed
goimports: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/goimports installed
golint: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/golint installed
gopls: /Users/xuzhiqiang/.gvm/pkgsets/go1.15/global/bin/gopls installed
go env
Workspace Folder (flash-pool): /Users/xuzhiqiang/Desktop/workspace/opensource/rust_exp/flash-pool
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xuzhiqiang/Library/Caches/go-build"
GOENV="/Users/xuzhiqiang/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/xuzhiqiang/.gvm/pkgsets/go1.15/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/xuzhiqiang/.gvm/pkgsets/go1.15/global"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/xuzhiqiang/.gvm/gos/go1.12"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/xuzhiqiang/.gvm/gos/go1.12/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ym/c42xcdhn78g0s97z3ycj2yw00000gn/T/go-build491264557=/tmp/go-build -gno-record-gcc-switches -fno-common"
Seems GOROOT
isn't changed somehow.
UPDATE
I found another issue: if the go project is embedded into a sub directory of a rust project, .vscode/settings.json
seems not taking effect at all.
@zhiqiangxu thanks for the updates. Based on the log, VSCode Go is seeing GOROOT: /Users/xuzhiqiang/.gvm/gos/go1.12
as the GOROOT
. You said the go version displayed in the status bar is still 1.15, right? That's puzzling.
I wonder if VSCode ran with the GOROOT
environment variable that points to go1.12
. (The extension changes the go binary search path but does not change the GOROOT
env var even with go.goroot
:-()
Can you open the developer tools and check the environment variables from there to make sure GOROOT is not set?
Command Palette -> Developer: Toggle Developer Tools
-> this will open the developer tools window.
-> Select Console
tab -> enter process.env["GOROOT"]
This should be undefined
.
(Nightly version](https://github.com/golang/vscode-go/blob/master/docs/nightly.md) has an option to enable more logging ("go.logging.level": "verbose"
in settings.json) that prints how the extension mutates the current GOROOT and chooses the binary.
Re: .vscode/settings.json
location - .vscode
directory must be under the project root directory (the directory you opened with vscode) and that's working as intended.
Ah , process.env["GOROOT"]
is /Users/xuzhiqiang/.gvm/gos/go1.12
in my PC.
Shouldn't the go.goroot
in settings.json
override the process.env["GOROOT"]
(just like go.gopath
overrides $GOPATH env)?
About the embeded case, the .vscode/settings.json
is under the project root directory, but the root project is rust, and the go.mod
lies under a sub directory of the root project, in this case, .vscode/settings.json
is not working as expected.
@zhiqiangxu Yes, go.goroot
does not override the GOROOT
environment variable any more but we choose the go
command from the specified goroot directory. The reasoning was that setting GOROOT
env var isn't a good idea in most cases, and the real GOROOT should be chosen by the go
command itself. (Mismatching the go
's GOROOT and GOROOT
env var historically caused many issues). But it looks like we should revisit this decision and evaluate more use cases.
Can you please tell us why you needed to set GOROOT
environment variable?
Re: .vscode/settings.json
, yeah, that's unfortunate - gopls
team is currently working on addressing the limitation so users can open the workspace from the true project root directory. Until then, either create .vscode/settings.json
under the go directory, or consider moving go.mod
to the project root.
I'm using gvm
to manage multiple go versions, and it internally sets GOROOT
environment variable.
UPDATE
This is the tool I'm using: https://github.com/moovweb/gvm
Thanks @zhiqiangxu
We were trying to deprecate go.goroot
and recommend setting through go.toolsEnvVars.GOROOT
. But soon realized that go.toolsEnvVars
is resource
-scoped - so env vars like CGO_CFLAGS can be sharable. But for GOROOT
, machine-overridable
scope is more suitable than resource
scope. It's unfortunate that there are many different ways to configure GOROOT, especially messing with GOROOT
isn't recommended any more. (I think gvm
should stop using/setting GOROOT
).
I will try to resurrect GOROOT setting through go.goroot
, but with a description of discouraging its use.
It was released as part of v0.25.0. I forgot to link the change https://go-review.googlesource.com/c/vscode-go/+/310853 commit
In my
settings.json
, I've to manually set thePATH
ingo.toolsEnvVars
:otherwise vscode will report:
cannot find module providing package crypto/ed25519
which is caused by selecting my default go version of
go1.12
(crypto/ed25519
is introduced ingo1.13
)It's should automatically infer the correct go path( in my case
/Users/xuzhiqiang/.gvm/gos/go1.15/bin/
) based ongo.gopath
andgo.goroot