go-nv / goenv

:blue_car: Like pyenv and rbenv, but for Go.
https://github.com/go-nv/goenv
MIT License
2.01k stars 245 forks source link

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

Open wakaryry opened 3 months ago

wakaryry commented 3 months ago

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.

reneleonhardt commented 1 month ago

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 commented 1 month ago

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

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

reneleonhardt commented 1 month ago

@ChronosMasterOfAllTime I saw multiple problems locally:

My expectation would be:

ChronosMasterOfAllTime commented 1 month ago

@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.