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

Prepend terminal PATH when go.goroot is set #544

Closed
segevfiner opened this issue Aug 18, 2020 · 11 comments
Closed

Prepend terminal PATH when go.goroot is set #544

segevfiner opened this issue Aug 18, 2020 · 11 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@segevfiner
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When using go.goroot to set an alternate Go version for a specific workspace, the terminal still uses the default PATH which leads the go command in the terminal to point to the default Go installation.

Describe the solution you'd like
Set the PATH in the terminal. (In a similar way to what is done when using Go: Choose Go Environment?)

Of course, this needs to be careful not to mangle the PATH, it should only really prepend the version and that's it, not set the entire variable.

Describe alternatives you've considered
Having to keep setting it manually...

@hyangah
Copy link
Contributor

hyangah commented Aug 18, 2020

@segevfiner I thought I fixed this long ago - unfortunately, it still needs the window reload. Or do you mean that the PATH should be mutated automatically when go.goroot is changed after the extension is activated?

@segevfiner
Copy link
Contributor Author

I have workspace where I set go.goroot in the workspace settings, it applies to stuff run by the vscode-go extension itself, but not in the integrated terminal of VS Code, after VS Code reload or otherwise. At least that's what I'm seeing.

VS Code 1.48.0 on macOS 1.14.6
vscode-go 1.16.1

@hyangah
Copy link
Contributor

hyangah commented Aug 18, 2020

Thanks. Strange that go.goroot is the one I use to choose different versions of go and this code that applies the PATH mutation should run before the go version statusbar is activated.
The go status bar has the right version of go, right?

Given that you are using macOS, I wonder if any of the conditions here (

} else if (!terminalCreationListener) { // process.platform === 'darwin'
// We don't use EnvironmentVariableCollection on mac
// because this gets confusing for users. Instead we send the
// shell command to change the PATH env var,
// following the suggestion to workaround described in
// https://github.com/microsoft/vscode/issues/99878#issuecomment-642808852
const terminalShellArgs = <string[]>(
vscode.workspace.getConfiguration('terminal.integrated.shellArgs').get('osx') || []);
// User explicitly chose to run the login shell. So, don't mess with their config.
if (!terminalShellArgs.includes('-l') && !terminalShellArgs.includes('--login')) {
) are true and prevent from applying the PATH mutation.

@hyangah
Copy link
Contributor

hyangah commented Aug 19, 2020

Thanks @segevfiner
Indeed I've been using with

    "terminal.integrated.shellArgs.osx": [
    ],

Maybe I misinterpreted the comment here microsoft/vscode#99878 (comment)
and we should've sent the export command if '-l' is set (i.e. true for macos by default :-()

@hyangah hyangah added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 19, 2020
@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/251161 mentions this issue: src/goEnvironmentStatus: fix PATH mutation logic in osx

@hyangah hyangah added this to the v0.17.0 milestone Aug 27, 2020
@burdiyan
Copy link

This fix completely broke my workflow with multiple Go versions for different workspaces.

I'm using Nix package manager and nix-shell + direnv for settings specific to projects. So I have one Go version installed globally with Nix and another one set with nix-shell for my project. It was working fine (because by default VS Code by default adds '-l' to shell arguments) for integrated terminal and PATH mutation was not invoked.

But now it mangles my PATH and overrides any Go version I've set in PATH with direnv by prepending my global Go version to my PATH.

I don't know why this is needed at all, why can't the extension just use whatever Go version is in the PATH without mutating it?

@segevfiner
Copy link
Contributor Author

Maybe it shouldn't do this when go.goroot is unset...

@burdiyan
Copy link

@segevfiner would be lovely!

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/256938 mentions this issue: src/goInstallTools.ts: mutate PATH only when necessary

gopherbot pushed a commit that referenced this issue Sep 25, 2020
When the extension chooses a different version of go
than the one from the system default - because the user
has configured `go.goroot` or `go.alternateTools.go`, or
used the `Go: Choose Go Environment` command - the extension
mutates the `PATH` (or `Path` on windows) environment variable
so all the underlying tools pick the same go version.
It also changes the environment variable collection used
in the integrated terminal so when the user invokes `go`
from the terminal, they use the go version consistent
with the extension.

But this behavior can conflict with external version
management software. Change the PATH environment only
if the extension is configured to choose the go binary.

Fixes #679.
Update #544.

Change-Id: I9f7acb26b752ed33dbde2b238a67ed09616b43e5
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/256938
Trust: Hyang-Ah Hana Kim <[email protected]>
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Suzy Mueller <[email protected]>
@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/258077 mentions this issue: [release] src/goInstallTools.ts: mutate PATH only when necessary

gopherbot pushed a commit that referenced this issue Sep 28, 2020
When the extension chooses a different version of go
than the one from the system default - because the user
has configured `go.goroot` or `go.alternateTools.go`, or
used the `Go: Choose Go Environment` command - the extension
mutates the `PATH` (or `Path` on windows) environment variable
so all the underlying tools pick the same go version.
It also changes the environment variable collection used
in the integrated terminal so when the user invokes `go`
from the terminal, they use the go version consistent
with the extension.

But this behavior can conflict with external version
management software. Change the PATH environment only
if the extension is configured to choose the go binary.

Fixes #679.
Update #544.

Change-Id: I9f7acb26b752ed33dbde2b238a67ed09616b43e5
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/256938
Trust: Hyang-Ah Hana Kim <[email protected]>
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Suzy Mueller <[email protected]>
(cherry picked from commit ab4b257)
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/258077
@golang golang locked and limited conversation to collaborators Sep 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants