src/goMain.ts: move setGOROOTEnvVar to goEnv

With setGOROOTEnvVar moved to goEnv, all exports besides
activate and deactive are now removed from goMain.ts.

Change-Id: Ic2a3bb8fc109f4e3e88b87b686870af972978b8e
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/405897
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/src/goEnv.ts b/src/goEnv.ts
index aebd903..eaddf9d 100644
--- a/src/goEnv.ts
+++ b/src/goEnv.ts
@@ -9,6 +9,8 @@
 import { getGoConfig } from './config';
 import { getCurrentGoPath, getToolsGopath, resolvePath } from './util';
 import { logVerbose } from './goLogging';
+import { dirExists } from './utils/pathUtils';
+import { getFromGlobalState, updateGlobalState } from './stateUtils';
 
 // toolInstallationEnvironment returns the environment in which tools should
 // be installed. It always returns a new object.
@@ -89,3 +91,42 @@
 	}
 	return env;
 }
+
+// set GOROOT env var. If necessary, shows a warning.
+export async function setGOROOTEnvVar(configGOROOT: string) {
+	if (!configGOROOT) {
+		return;
+	}
+	const goroot = configGOROOT ? resolvePath(configGOROOT) : undefined;
+
+	const currentGOROOT = process.env['GOROOT'];
+	if (goroot === currentGOROOT) {
+		return;
+	}
+	if (!(await dirExists(goroot ?? ''))) {
+		vscode.window.showWarningMessage(`go.goroot setting is ignored. ${goroot} is not a valid GOROOT directory.`);
+		return;
+	}
+	const neverAgain = { title: "Don't Show Again" };
+	const ignoreGOROOTSettingWarningKey = 'ignoreGOROOTSettingWarning';
+	const ignoreGOROOTSettingWarning = getFromGlobalState(ignoreGOROOTSettingWarningKey);
+	if (!ignoreGOROOTSettingWarning) {
+		vscode.window
+			.showInformationMessage(
+				`"go.goroot" setting (${goroot}) will be applied and set the GOROOT environment variable.`,
+				neverAgain
+			)
+			.then((result) => {
+				if (result === neverAgain) {
+					updateGlobalState(ignoreGOROOTSettingWarningKey, true);
+				}
+			});
+	}
+
+	logVerbose(`setting GOROOT = ${goroot} (old value: ${currentGOROOT}) because "go.goroot": "${configGOROOT}"`);
+	if (goroot) {
+		process.env['GOROOT'] = goroot;
+	} else {
+		delete process.env.GOROOT;
+	}
+}
diff --git a/src/goMain.ts b/src/goMain.ts
index f0dd296..b102d6a 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -22,7 +22,7 @@
 } from './goCover';
 import { GoDebugConfigurationProvider } from './goDebugConfiguration';
 import * as GoDebugFactory from './goDebugFactory';
-import { toolExecutionEnvironment } from './goEnv';
+import { setGOROOTEnvVar, toolExecutionEnvironment } from './goEnv';
 import {
 	chooseGoEnvironment,
 	offerToInstallLatestGoVersion,
@@ -35,7 +35,7 @@
 import { offerToInstallTools, promptForMissingTool, updateGoVarsFromConfig, suggestUpdates } from './goInstallTools';
 import { RestartReason, showServerOutputChannel, watchLanguageServerConfiguration } from './language/goLanguageServer';
 import { lintCode } from './goLint';
-import { logVerbose, setLogConfig } from './goLogging';
+import { setLogConfig } from './goLogging';
 import { GO_MODE } from './goMode';
 import { GO111MODULE, goModInit, isModSupported } from './goModules';
 import { playgroundCommand } from './goPlayground';
@@ -54,7 +54,7 @@
 } from './stateUtils';
 import { cancelRunningTests, showTestOutput } from './testUtils';
 import { cleanupTempDir, getBinPath, getToolsGopath, isGoPathSet, resolvePath } from './util';
-import { clearCacheForTools, dirExists } from './utils/pathUtils';
+import { clearCacheForTools } from './utils/pathUtils';
 import { WelcomePanel } from './welcome';
 import vscode = require('vscode');
 import { getFormatTool } from './language/legacy/goFormat';
@@ -371,45 +371,6 @@
 	return `go-${lintToolName}`;
 }
 
-// set GOROOT env var. If necessary, shows a warning.
-export async function setGOROOTEnvVar(configGOROOT: string) {
-	if (!configGOROOT) {
-		return;
-	}
-	const goroot = configGOROOT ? resolvePath(configGOROOT) : undefined;
-
-	const currentGOROOT = process.env['GOROOT'];
-	if (goroot === currentGOROOT) {
-		return;
-	}
-	if (!(await dirExists(goroot ?? ''))) {
-		vscode.window.showWarningMessage(`go.goroot setting is ignored. ${goroot} is not a valid GOROOT directory.`);
-		return;
-	}
-	const neverAgain = { title: "Don't Show Again" };
-	const ignoreGOROOTSettingWarningKey = 'ignoreGOROOTSettingWarning';
-	const ignoreGOROOTSettingWarning = getFromGlobalState(ignoreGOROOTSettingWarningKey);
-	if (!ignoreGOROOTSettingWarning) {
-		vscode.window
-			.showInformationMessage(
-				`"go.goroot" setting (${goroot}) will be applied and set the GOROOT environment variable.`,
-				neverAgain
-			)
-			.then((result) => {
-				if (result === neverAgain) {
-					updateGlobalState(ignoreGOROOTSettingWarningKey, true);
-				}
-			});
-	}
-
-	logVerbose(`setting GOROOT = ${goroot} (old value: ${currentGOROOT}) because "go.goroot": "${configGOROOT}"`);
-	if (goroot) {
-		process.env['GOROOT'] = goroot;
-	} else {
-		delete process.env.GOROOT;
-	}
-}
-
 async function showDeprecationWarning() {
 	// Present a warning about the deprecation of the go.documentLink setting.
 	const experimentalFeatures = getGoConfig()['languageServerExperimentalFeatures'];
diff --git a/test/integration/statusbar.test.ts b/test/integration/statusbar.test.ts
index e6f669d..0954bfe 100644
--- a/test/integration/statusbar.test.ts
+++ b/test/integration/statusbar.test.ts
@@ -27,7 +27,7 @@
 
 import ourutil = require('../../src/util');
 import { GoExtensionContext } from '../../src/context';
-import { setGOROOTEnvVar } from '../../src/goMain';
+import { setGOROOTEnvVar } from '../../src/goEnv';
 
 describe('#initGoStatusBar()', function () {
 	this.beforeAll(async () => {