src/goMain.ts: move the go installation suggestion out of the critical path

This slows down the activation. One side effect is to start language server
later. This doesn't have to be on the critical path, and also updateGoVarsFromConfig
will soon do the same.

updateGoVarsFromConfig will check the go binary asynchronously
and suggest download upon detecting the issue.

And while we are here, remove the code that prevents updateGoVarsFromConfig
from running when some environment variables are set. updateGoVarsFromConfig
is called upon activation & when the relevant configuration fields are updated.
So, I suppose this is called rarely, and also it's right to reprocess and
update relevant info.

Update golang/vscode-go#363

Change-Id: I65a50915630d3d68d892ca267d248cd42958b9fb
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/243280
Reviewed-by: Brayden Cloud <bcloud@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts
index 9a2d81a..96beb02 100644
--- a/src/goInstallTools.ts
+++ b/src/goInstallTools.ts
@@ -339,20 +339,11 @@
 }
 
 export function updateGoVarsFromConfig(): Promise<void> {
-	// FIXIT: when user changes the environment variable settings or go.gopath, the following
-	// condition prevents from updating the process.env accordingly, so the extension will lie.
-	// Needs to clean up.
-	if (process.env['GOPATH'] && process.env['GOPROXY'] && process.env['GOBIN']) {
-		return Promise.resolve();
-	}
-
 	// FIXIT: if updateGoVarsFromConfig is called again after addGoRuntimeBaseToPATH sets PATH,
 	// the go chosen by getBinPath based on PATH will not change.
 	const goRuntimePath = getBinPath('go', false);
 	if (!goRuntimePath) {
-		vscode.window.showErrorMessage(
-			`Failed to run "go env" to find GOPATH as the "go" binary cannot be found in either GOROOT(${getCurrentGoRoot()}) or PATH(${envPath})`
-		);
+		suggestDownloadGo();
 		return;
 	}
 
@@ -505,3 +496,24 @@
 		return res.filter((x) => x != null);
 	});
 }
+
+let suggestedDownloadGo = false;
+
+async function suggestDownloadGo() {
+	if (suggestedDownloadGo) {
+		vscode.window.showErrorMessage(
+			`Failed to find the "go" binary in either GOROOT(${getCurrentGoRoot()}) or PATH(${envPath}).`
+		);
+		return;
+	}
+
+	const choice = await vscode.window.showErrorMessage(
+		`Failed to find the "go" binary in either GOROOT(${getCurrentGoRoot()}) or PATH(${envPath}. ` +
+		`Check PATH, or Install Go and reload the window.`,
+		'Go to Download Page'
+	);
+	if (choice === 'Go to Download Page') {
+		vscode.env.openExternal(vscode.Uri.parse('https://golang.org/dl/'));
+	}
+	suggestedDownloadGo = true;
+}
diff --git a/src/goMain.ts b/src/goMain.ts
index bcf5031..16e04a7 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -70,19 +70,7 @@
 // the configuration of the server.
 export let restartLanguageServer = () => { return; };
 
-export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
-	if (!getBinPath('go', false)) {
-		const choice = await vscode.window.showInformationMessage(
-			`Go could not be found in either GOROOT(${getCurrentGoRoot()}) or PATH(${envPath}. ` +
-			`Install Go and reload the window.`,
-			'Go to Download Page'
-		);
-		if (choice === 'Go to Download Page') {
-			vscode.env.openExternal(vscode.Uri.parse('https://golang.org/dl/'));
-		}
-		return;
-	}
-
+export function activate(ctx: vscode.ExtensionContext) {
 	setGlobalState(ctx.globalState);
 	setWorkspaceState(ctx.workspaceState);
 	const configGOROOT = getGoConfig()['goroot'];