fix: apply shell integration for environment variables

Apply shell integration to ensure extension environment variables
like PATH take precedence over user exports in shell startup files.

Fixes golang/vscode-go#3975

Change-Id: Ifa0cdde710ac6afddc61cf99ed582bade62b78ab
GitHub-Last-Rev: 331024ba1a5e8773828b1f717c0d2a754d33c0a7
GitHub-Pull-Request: golang/vscode-go#3972
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/736764
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
Reviewed-by: Madeline Kalil <mkalil@google.com>
Auto-Submit: Hongxiang Jiang <hxjiang@golang.org>
diff --git a/extension/src/goEnvironmentStatus.ts b/extension/src/goEnvironmentStatus.ts
index 4ed4203..42020ed 100644
--- a/extension/src/goEnvironmentStatus.ts
+++ b/extension/src/goEnvironmentStatus.ts
@@ -305,6 +305,15 @@
 }
 
 /**
+ * These options overwrite profiles such as `.bashrc`.
+ * Users who do not want this behavior should set `go.terminal.activateEnvironment` to `false`.
+ */
+const envVarMutatorOptions: vscode.EnvironmentVariableMutatorOptions = {
+	applyAtProcessCreation: true,
+	applyAtShellIntegration: true
+};
+
+/**
  * addGoRuntimeBaseToPATH adds the given path to the front of the PATH
  * environment variable. It removes duplicates.
  * TODO: can we avoid changing PATH but utilize toolExecutionEnv?
@@ -333,7 +342,7 @@
 	// Calling this multiple times will override the previous value.
 	// environmentVariableCollection.clear();
 	if (process.platform !== 'darwin') {
-		environmentVariableCollection?.prepend(pathEnvVar, newGoRuntimeBase + path.delimiter);
+		environmentVariableCollection?.prepend(pathEnvVar, newGoRuntimeBase + path.delimiter, envVarMutatorOptions);
 	} else {
 		// When '-l' or '--login' flags are set, the terminal will invoke a login
 		// shell again and the paths from the user's login shell will be prepended
@@ -355,7 +364,7 @@
 			}
 			terminalCreationListener = vscode.window.onDidOpenTerminal(updateIntegratedTerminal);
 		} else {
-			environmentVariableCollection?.prepend(pathEnvVar, newGoRuntimeBase + path.delimiter);
+			environmentVariableCollection?.prepend(pathEnvVar, newGoRuntimeBase + path.delimiter, envVarMutatorOptions);
 		}
 	}