goenv
goenv copied to clipboard
Switching Go version when process.env["GOROOT"] is set is unsupported.
How can I make it work correct on VSCODE?
Apple M2 Pro;
VSCODE: Version: 1.87.2
If I set goenv global, the vscode will always use the global set. I can not change it into the local go version.
I must change the global and reload the vscode.
I can not work with vscode using other go versions.
Thanks.
Hello @wakaryry sorry for the late reply, could you elaborate a bit more about your setup?
I don't know all of the logic yet, I understand that your problem is local not working when global and GOROOT are both set? Are local and global showing the correct (different) values?
I couldn't reproduce this yet, we have over 300 test cases... did you follow the INSTALL.md (especially 4. goenv manages GOROOT), ENVIRONMENT_VARIABLES.md (especially GOENV_DISABLE_GOROOT) and CHANGELOG.md 2.0.0beta6 (goenv rehash)? Did you install into .bash_profile or .bashrc (see 4.)?
Can you post $ env | grep GO in your local folder / environment?
I don't know enough about all inner workings, goenv local works, but global does not.
goenv local 1.22.3goenv root# copy that path, usually the result of your user$HOME/.goenv- Go to Settings / Extensions / Go
- Alternate Tools: Edit in settings.json
- Change the block to the copied path and append
/shims
"go.alternateTools": {
"go": "/Users/myuser/.goenv/shims"
}
exec $SHELL# or open a new terminalgo version# should show go1.22.3
Everytime you change goenv local you should run exec $SHELL or open a new terminal.
@ChronosMasterOfAllTime I saw multiple problems locally:
- There was a $HOME/.go-version file (maybe from local development?), so even after
goenv local --unsetthe code usesgoenv version-file $PWDwhich is allowed to search all the way up to that folder sogoenv localstill showed that version (1.21.10) - After I deleted that file manually,
goenv local(unset) andgoenv global(1.22.3) worked - After
goenv global systemI found no way to update the shims withgoenv rehash, they still pointed to the old global, so system (1.22.4) can't be used inside the shims folder
My expectation would be:
goenv localonly respects the "local" folder $PWD/.go-version (goenv version-file $PWDshould not search all the way up until $HOME/.go-version, only inside the project folder if currently inside a subdirectory, otherwise that would be a local global version 😅)goenv local --unsetallowsgoenv globalto use ${GOENV_ROOT}/version (goenv version-fileshould find it, this is working)goenv global systemshould rehash the shims to use the system Go if installed (and--unsetshould be added to be symmetrical tolocal)goenv localandgoenv globalshould rehash the shims in general after aninstalledversion has been setgoenv localandgoenv globalshould callexec $SHELL(or -l) if configured by the user (internally a newreloadcommand) Then VS Code users could be happy again 😄
@ChronosMasterOfAllTime I saw multiple problems locally:
- There was a $HOME/.go-version file (maybe from local development?), so even after
goenv local --unsetthe code usesgoenv version-file $PWDwhich is allowed to search all the way up to that folder sogoenv localstill showed that version (1.21.10)- After I deleted that file manually,
goenv local(unset) andgoenv global(1.22.3) worked- After
goenv global systemI found no way to update the shims withgoenv rehash, they still pointed to the old global, so system (1.22.4) can't be used inside the shims folderMy expectation would be:
goenv localonly respects the "local" folder $PWD/.go-version (goenv version-file $PWDshould not search all the way up until $HOME/.go-version, only inside the project folder if currently inside a subdirectory, otherwise that would be a local global version 😅)goenv local --unsetallowsgoenv globalto use ${GOENV_ROOT}/version (goenv version-fileshould find it, this is working)goenv global systemshould rehash the shims to use the system Go if installed (and--unsetshould be added to be symmetrical tolocal)goenv localandgoenv globalshould rehash the shims in general after aninstalledversion has been setgoenv localandgoenv globalshould callexec $SHELL(or -l) if configured by the user (internally a newreloadcommand) Then VS Code users could be happy again 😄
Nice find! I would certainly welcome a PR since you did a solid job of RCA'ing this.