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

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

Open
wakaryry opened this issue Mar 26, 2024 · 4 comments
Open

Comments

@wakaryry
Copy link

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
Copy link
Contributor

reneleonhardt commented Jun 5, 2024

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
Copy link
Contributor

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
Copy link
Contributor

reneleonhardt commented Jun 6, 2024

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

@ChronosMasterOfAllTime
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants