Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statusbar indicates wrong Go version #2219

Closed
mixedCase opened this issue Apr 27, 2022 · 4 comments
Closed

Statusbar indicates wrong Go version #2219

mixedCase opened this issue Apr 27, 2022 · 4 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@mixedCase
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.18 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
Build info
----------
golang.org/x/tools/gopls v0.8.1
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/toml@v1.0.0
    github.com/google/go-cmp@v0.5.7
    github.com/sergi/go-diff@v1.1.0
    golang.org/x/mod@v0.6.0-dev.0.20220106191415-9b9b3d81d5e3
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c
    golang.org/x/sys@v0.0.0-20220209214540-3681064d5158
    golang.org/x/text@v0.3.7
    golang.org/x/tools@v0.1.10-0.20220315142906-0c66750444e6
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1
    honnef.co/go/tools@v0.2.2
    mvdan.cc/gofumpt@v0.3.0
    mvdan.cc/xurls/v2@v2.4.0
go: go1.18
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
1.66.2
dfd34e8260c270da74b5c2d86d61aee4b6d56977
x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.32.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /home/mixedcase/go
GOROOT: /nix/store/njs424yyxxjhxibkpx5m36flr26nzzn6-go-1.17.8/share/go
PATH: /nix/store/9gjpz9b7vm450n1hpflgj4lqm4l7qx6l-bash-interactive-5.1-p16/bin:/nix/store/9chsm1gqvvpqywz219s1rknfrzr5xjfz-patchelf-0.14.3/bin:/nix/store/jz10kjr0lnhynwxnrzv4kcwbjs5s0ri8-gcc-wrapper-10.3.0/bin:/nix/store/finlf6zyxhpqi8hp2p4fgxkgqvjp6l78-gcc-10.3.0/bin:/nix/store/drb5a0j2z8fh6bivl9aq15fbfmrx62kb-glibc-2.33-117-bin/bin:/nix/store/2w6011wwg5v6qxz182r4d0mmr3i4rxm1-coreutils-9.0/bin:/nix/store/55ayck4pllh4qallb1dbhbkrzwrrl02r-binutils-wrapper-2.35.2/bin:/nix/store/x2zbyl2l4xayv4d5is0b31plfq8xjjym-binutils-2.35.2/bin:/nix/store/xgibf1z6b7zx4h1hv3v8qw0f2n1jv4pm-gnumake-4.3/bin:/nix/store/ngv92md1x8fvay76v85biablz7wvlbj4-go-1.18/bin:/nix/store/lps3d84ycj2b7f8h3w3ijk4fy0jhhwm4-gopls-0.8.1/bin:/nix/store/xb0pwk6pjcy0akxsnq3rlc8aijr8v2r8-buf-1.3.0/bin:/nix/store/xsyxl03j9k5cnrnzpffd2ccykn5q8kv7-clang-tools-13.0.1/bin:/nix/store/2w6011wwg5v6qxz182r4d0mmr3i4rxm1-coreutils-9.0/bin:/nix/store/pr0l0cwak2dprcvvzqvli1kkpg7k9fci-findutils-4.9.0/bin:/nix/store/c5xa1n6bl34gxfmjlqgaxdyk4i583fk5-diffutils-3.8/bin:/nix/store/jdhk02s01ca02qv083f41wz8jj25gybc-gnused-4.8/bin:/nix/store/3fvq0jjjh50vh0rlqr2xc9ya8llcj113-gnugrep-3.7/bin:/nix/store/i4mm5ycljiq465ncr29mg9bf7wn18i8c-gawk-5.1.1/bin:/nix/store/4rypjibv28cbbg21apsqnnyi3k2glzjd-gnutar-1.34/bin:/nix/store/660k06nr64g3fqndivn6brmk8ly7ivdz-gzip-1.11/bin:/nix/store/rmxjjpg43f6jssh82q29q21lzlcqzwxz-bzip2-1.0.6.0.2-bin/bin:/nix/store/xgibf1z6b7zx4h1hv3v8qw0f2n1jv4pm-gnumake-4.3/bin:/nix/store/dndi916j6yxzfzzj2sma2llhrlwahq06-bash-5.1-p16/bin:/nix/store/agfkd1d9mmcniwrvh10afn054x1n8iqi-patch-2.7.6/bin:/nix/store/45j7wibbdckl5f50bs5nq7damhy8cahp-xz-5.2.5-bin/bin:/nix/store/xl4fcwa76r0xy59dlhjvvj7h0nl0ix84-glib-2.72.0-bin/bin:/home/mixedcase/.local/share/npm-packages/bin:/home/mixedcase/bin:/run/wrappers/bin:/home/mixedcase/.local/share/flatpak/exports/bin:/var/lib/flatpak/exports/bin:/home/mixedcase/.nix-profile/bin:/etc/profiles/per-user/mixedcase/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin
PATH (vscode launched with): /nix/store/xl4fcwa76r0xy59dlhjvvj7h0nl0ix84-glib-2.72.0-bin/bin:/home/mixedcase/.local/share/npm-packages/bin:/home/mixedcase/bin:/run/wrappers/bin:/home/mixedcase/.local/share/flatpak/exports/bin:/var/lib/flatpak/exports/bin:/home/mixedcase/.nix-profile/bin:/etc/profiles/per-user/mixedcase/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin

	go:	/run/current-system/sw/bin/go: go version go1.17.8 linux/amd64

	go-outline:	/home/mixedcase/go/bin/go-outline	(version: unknown - )
	gotests:	/home/mixedcase/go/bin/gotests	(version: unknown - )
	gomodifytags:	/home/mixedcase/go/bin/gomodifytags	(version: unknown - )
	impl:	/home/mixedcase/go/bin/impl	(version: unknown - )
	goplay:	/home/mixedcase/go/bin/goplay	(version: unknown - )
	dlv:	/home/mixedcase/go/bin/dlv	(version: unknown - )
	staticcheck:	/home/mixedcase/go/bin/staticcheck	(version: unknown - )
	gopls:	/home/mixedcase/go/bin/gopls	(version: unknown - )

go env
Workspace Folder (REDACTED): REDACTED
	GO111MODULE=""
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/home/mixedcase/.cache/go-build"
	GOENV="/home/mixedcase/.config/go/env"
	GOEXE=""
	GOEXPERIMENT=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="linux"
	GOINSECURE=""
	GOMODCACHE="/home/mixedcase/go/pkg/mod"
	GONOPROXY=REDACTED
	GONOSUMDB=REDACTED
	GOOS="linux"
	GOPATH="/home/mixedcase/go"
	GOPRIVATE=REDACTED
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/nix/store/njs424yyxxjhxibkpx5m36flr26nzzn6-go-1.17.8/share/go"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/nix/store/njs424yyxxjhxibkpx5m36flr26nzzn6-go-1.17.8/share/go/pkg/tool/linux_amd64"
	GOVCS=""
	GOVERSION="go1.17.8"
	GCCGO="gccgo"
	AR="ar"
	CC="gcc"
	CXX="g++"
	CGO_ENABLED="1"
	GOMOD=REDACTED
	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 -fmessage-length=0 -fdebug-prefix-map=/run/user/1000/go-build556048919=/tmp/go-build -gno-record-gcc-switches"

Share the Go related settings you have added/edited

"go.toolsManagement.checkForUpdates": "off",
"go.alternateTools": {
    "go": "go"
}

Removing go.alternateTools changes nothing, it was just an attempt to get the plugin to look properly into the PATH instead of doing whatever it's doing.

Describe the bug

The status bar at the bottom indicates the wrong Go version. I am using Nix Env Selector to load a nix shell full of development tools into the VS Code environment, including Go 1.18, which is reflected by the right gopls running which is evidenced by both Go 1.18-specific syntax being recognized, and by the following log in the Electron Console:

[Extension Host] Server: {  "Commands": [    "gopls.add_dependency",    "gopls.add_import",    "gopls.apply_fix",    "gopls.check_upgrades",    "gopls.edit_go_directive",    "gopls.gc_details",    "gopls.generate",    "gopls.generate_gopls_mod",    "gopls.go_get_package",    "gopls.list_imports",    "gopls.list_known_packages",    "gopls.regenerate_cgo",    "gopls.remove_dependency",    "gopls.run_tests",    "gopls.start_debugging",    "gopls.test",    "gopls.tidy",    "gopls.toggle_gc_details",    "gopls.update_go_sum",    "gopls.upgrade_dependency",    "gopls.vendor"  ],  "Name": "gopls",  "Version": "v0.8.1",  "GoVersion": "go1.18"}

However, the version selector seems to be getting tools from a different PATH, showing instead Go 1.17, which is the version my system has globally installed, and, while present in PATH, it should've been overridden by the folder /nix/store/ngv92md1x8fvay76v85biablz7wvlbj4-go-1.18/bin which is earlier in my PATH:

/nix/store/9chsm1gqvvpqywz219s1rknfrzr5xjfz-patchelf-0.14.3/bin:/nix/store/jz10kjr0lnhynwxnrzv4kcwbjs5s0ri8-gcc-wrapper-10.3.0/bin:/nix/store/finlf6zyxhpqi8hp2p4fgxkgqvjp6l78-gcc-10.3.0/bin:/nix/store/drb5a0j2z8fh6bivl9aq15fbfmrx62kb-glibc-2.33-117-bin/bin:/nix/store/2w6011wwg5v6qxz182r4d0mmr3i4rxm1-coreutils-9.0/bin:/nix/store/55ayck4pllh4qallb1dbhbkrzwrrl02r-binutils-wrapper-2.35.2/bin:/nix/store/x2zbyl2l4xayv4d5is0b31plfq8xjjym-binutils-2.35.2/bin:/nix/store/xgibf1z6b7zx4h1hv3v8qw0f2n1jv4pm-gnumake-4.3/bin:/nix/store/ngv92md1x8fvay76v85biablz7wvlbj4-go-1.18/bin:/nix/store/xb0pwk6pjcy0akxsnq3rlc8aijr8v2r8-buf-1.3.0/bin:/nix/store/xsyxl03j9k5cnrnzpffd2ccykn5q8kv7-clang-tools-13.0.1/bin:/nix/store/2w6011wwg5v6qxz182r4d0mmr3i4rxm1-coreutils-9.0/bin:/nix/store/pr0l0cwak2dprcvvzqvli1kkpg7k9fci-findutils-4.9.0/bin:/nix/store/c5xa1n6bl34gxfmjlqgaxdyk4i583fk5-diffutils-3.8/bin:/nix/store/jdhk02s01ca02qv083f41wz8jj25gybc-gnused-4.8/bin:/nix/store/3fvq0jjjh50vh0rlqr2xc9ya8llcj113-gnugrep-3.7/bin:/nix/store/i4mm5ycljiq465ncr29mg9bf7wn18i8c-gawk-5.1.1/bin:/nix/store/4rypjibv28cbbg21apsqnnyi3k2glzjd-gnutar-1.34/bin:/nix/store/660k06nr64g3fqndivn6brmk8ly7ivdz-gzip-1.11/bin:/nix/store/rmxjjpg43f6jssh82q29q21lzlcqzwxz-bzip2-1.0.6.0.2-bin/bin:/nix/store/xgibf1z6b7zx4h1hv3v8qw0f2n1jv4pm-gnumake-4.3/bin:/nix/store/dndi916j6yxzfzzj2sma2llhrlwahq06-bash-5.1-p16/bin:/nix/store/agfkd1d9mmcniwrvh10afn054x1n8iqi-patch-2.7.6/bin:/nix/store/45j7wibbdckl5f50bs5nq7damhy8cahp-xz-5.2.5-bin/bin:/home/mixedcase/.local/share/npm-packages/bin:/nix/store/xl4fcwa76r0xy59dlhjvvj7h0nl0ix84-glib-2.72.0-bin/bin:/home/mixedcase/bin:/run/wrappers/bin:/home/mixedcase/.local/share/flatpak/exports/bin:/var/lib/flatpak/exports/bin:/home/mixedcase/.nix-profile/bin:/etc/profiles/per-user/mixedcase/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin

(first bold is what it should be using, last bold is where it's getting it from)

My guesses are that:

a) The version selector is reading PATH wrong.
b) It is hooking its initialization before Nix Env Selector for some reason, and this makes it pick up the wrong PATH.

A successful workaround for this is to load the Nix environment inside a terminal and launching VS Code from there, which makes me think option b is more likely.

Steps to reproduce the behavior:

  1. Get nix-env-selector plugin
  2. Load with it a shell.nix which loads a version of Go different than the system's
  3. Reload VS Code as per Nix Env Selector's request
  4. Watch the Go plugin mix Go versions, indicating one thing in the version selector, but doing another
@gopherbot gopherbot added this to the Untriaged milestone Apr 27, 2022
@hyangah
Copy link
Contributor

hyangah commented Apr 27, 2022

PATH (vscode launched with): 
/nix/store/xl4fcwa76r0xy59dlhjvvj7h0nl0ix84-glib-2.72.0-bin/bin:
/home/mixedcase/.local/share/npm-packages/bin:/home/mixedcase/bin:
/run/wrappers/bin:/home/mixedcase/.local/share/flatpak/exports/bin:
/var/lib/flatpak/exports/bin:/home/mixedcase/.nix-profile/bin:
/etc/profiles/per-user/mixedcase/bin:
/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin

From the log in the report, I see that the vscode was launched with the above path. No go1.18 path present when the extension started.

This log message tells the gopls was built with go1.18, and doesn't mean that it found go 1.18 toolchain.

[Extension Host] Server: {  "Commands": [   ...  ],  "Name": "gopls",  "Version": "v0.8.1",  "GoVersion": "go1.18"}

This extension has no knowledge of what nix-env-selector but inherits the environment from the vscode extension host it runs on. This matches your guess b.

Last time I checked microsoft/vscode#46846 I couldn't find a good way of solving it.
Is there now a solution? Maybe can the nix-env-selector plugin authors give some advice on how to workaround?

@hyangah hyangah added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 27, 2022
@mixedCase
Copy link
Author

Reading the code, all nix-env-selector does is load the environment using nix-shell, parse the environment variables from it, and sets them on process.env during activation.

It is set to first activate on all VS Code events and loads quickly so it has the highest chance to load first/near the beginning, but indeed, it seems there's no way to guarantee the Go extension will load after it.

Is this PATH "vscode launched with" something that is captured at the time of Go extension init, or is it a separate variable that VS Code makes available (as in, the PATH that vscode truly launched with, before any extension loaded) and the Go extension prefers over the current process.env? If the latter, why does it do that? If not, then there would probably be a need for something like a synchronous load order API or user setting in VS Code, to allow specific extensions to fully activate in a specific order before everything else.

@hyangah
Copy link
Contributor

hyangah commented Apr 28, 2022

It's process.env captured when the extension is loaded (before 'activate' call though).

If it's safe to assume nix-env-selector will be activated before go extension (can you check the activation sequence from "Log (Extension Host)" OUTPUT? ), maybe we can try to delay to read process.env when activate runs.

However, given that the code was introduced long ago and this is referenced in many places in very subtle ways, I wouldn't be surprised if it is not as easy as it seems.

@hyangah hyangah modified the milestones: Untriaged, On Deck Apr 28, 2022
@hyangah hyangah added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 9, 2022
@gopherbot
Copy link
Collaborator

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants