goenv icon indicating copy to clipboard operation
goenv copied to clipboard

Switching Go version when process.env["GOROOT"] is set is unsupported.

Open wakaryry opened this issue 1 year ago • 4 comments
trafficstars

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.

wakaryry avatar Mar 26 '24 08:03 wakaryry

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?

reneleonhardt avatar Jun 05 '24 20:06 reneleonhardt

I don't know enough about all inner workings, goenv local works, but global does not.

  • goenv local 1.22.3
  • goenv 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 terminal
  • go version # should show go1.22.3

Everytime you change goenv local you should run exec $SHELL or open a new terminal.

reneleonhardt avatar Jun 06 '24 05:06 reneleonhardt

@ChronosMasterOfAllTime I saw multiple problems locally:

  • There was a $HOME/.go-version file (maybe from local development?), so even after goenv local --unset the code uses goenv version-file $PWD which is allowed to search all the way up to that folder so goenv local still showed that version (1.21.10)
  • After I deleted that file manually, goenv local (unset) and goenv global (1.22.3) worked
  • After goenv global system I found no way to update the shims with goenv 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 local only respects the "local" folder $PWD/.go-version (goenv version-file $PWD should 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 --unset allows goenv global to use ${GOENV_ROOT}/version (goenv version-file should find it, this is working)
  • goenv global system should rehash the shims to use the system Go if installed (and --unset should be added to be symmetrical to local)
  • goenv local and goenv global should rehash the shims in general after an installed version has been set
  • goenv local and goenv global should call exec $SHELL (or -l) if configured by the user (internally a new reload command) Then VS Code users could be happy again 😄

reneleonhardt avatar Jun 06 '24 06:06 reneleonhardt

@ChronosMasterOfAllTime I saw multiple problems locally:

  • There was a $HOME/.go-version file (maybe from local development?), so even after goenv local --unset the code uses goenv version-file $PWD which is allowed to search all the way up to that folder so goenv local still showed that version (1.21.10)
  • After I deleted that file manually, goenv local (unset) and goenv global (1.22.3) worked
  • After goenv global system I found no way to update the shims with goenv 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 local only respects the "local" folder $PWD/.go-version (goenv version-file $PWD should 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 --unset allows goenv global to use ${GOENV_ROOT}/version (goenv version-file should find it, this is working)
  • goenv global system should rehash the shims to use the system Go if installed (and --unset should be added to be symmetrical to local)
  • goenv local and goenv global should rehash the shims in general after an installed version has been set
  • goenv local and goenv global should call exec $SHELL (or -l) if configured by the user (internally a new reload command) 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.

ChronosMasterOfAllTime avatar Jun 06 '24 14:06 ChronosMasterOfAllTime