extension/src/welcome: readd the fix for go.showWelcome handling

The original fix for golang/vscode-go#3319 also included
a minor refactoring attempt - centralize welcome page show logic
in shouldShowGoWelcomePage. But that unfortunately introduced
a new bug, i.e., failed to apply the Web-based IDE exclusion rule
correctly.

Reverted the previous change to remove the refactoring.
And, this change adds the specific fix to address the bug reported
in golang/vscode-go#3319.

Test coverage would be nice, but it is tricky without
major refactoring or complicating test logic to stub or
inject dependencies.

Renamed shouldShowGoWelcomePage to make it clear that
this is to decide whether we have news to show purely
based on the extension's version.

For golang/vscode-go#3319.

Change-Id: Ia4915e0201e73d136b3efcec7c0cf4f5a5e4559f
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/581118
kokoro-CI: kokoro <noreply+kokoro@google.com>
Commit-Queue: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
diff --git a/extension/src/welcome.ts b/extension/src/welcome.ts
index b0afe12..f20379b 100644
--- a/extension/src/welcome.ts
+++ b/extension/src/welcome.ts
@@ -12,7 +12,7 @@
 import semver = require('semver');
 import { extensionId } from './const';
 import { GoExtensionContext } from './context';
-import { extensionInfo } from './config';
+import { extensionInfo, getGoConfig } from './config';
 import { getFromGlobalState, updateGlobalState } from './stateUtils';
 import { createRegisterCommand } from './commands';
 
@@ -30,8 +30,14 @@
 			});
 		}
 
-		// Show the Go welcome page on update.
-		if (!extensionInfo.isInCloudIDE && vscode.workspace.getConfiguration('go.showWelcome')) {
+		// Show the Go welcome page on update unless one of the followings is true:
+		//   * the extension is running in Cloud IDE or
+		//   * the user explicitly opted out (go.showWelcome === false)
+		//
+		// It is difficult to write useful tests for this suppression logic
+		// without major refactoring or complicating tests to enable
+		// dependency injection or stubbing.
+		if (!extensionInfo.isInCloudIDE && getGoConfig().get('showWelcome') !== false) {
 			showGoWelcomePage();
 		}
 	}
@@ -269,7 +275,7 @@
 
 	const savedGoExtensionVersion = getFromGlobalState(goExtensionVersionKey, '');
 
-	if (shouldShowGoWelcomePage(showVersions, goExtensionVersion, savedGoExtensionVersion)) {
+	if (hasNewsForNewVersion(showVersions, goExtensionVersion, savedGoExtensionVersion)) {
 		vscode.commands.executeCommand('go.welcome');
 	}
 	if (goExtensionVersion !== savedGoExtensionVersion) {
@@ -277,7 +283,7 @@
 	}
 }
 
-export function shouldShowGoWelcomePage(showVersions: string[], newVersion: string, oldVersion: string): boolean {
+export function hasNewsForNewVersion(showVersions: string[], newVersion: string, oldVersion: string): boolean {
 	if (newVersion === oldVersion) {
 		return false;
 	}
diff --git a/extension/test/integration/welcome.test.ts b/extension/test/integration/welcome.test.ts
index 78afe71..8a530c4 100644
--- a/extension/test/integration/welcome.test.ts
+++ b/extension/test/integration/welcome.test.ts
@@ -5,7 +5,7 @@
 
 import vscode = require('vscode');
 import assert from 'assert';
-import { shouldShowGoWelcomePage } from '../../src/welcome';
+import { hasNewsForNewVersion } from '../../src/welcome';
 import { extensionId } from '../../src/const';
 import { WelcomePanel } from '../../src/welcome';
 
@@ -54,7 +54,7 @@
 		const [showVersions, newVersion, oldVersion, expected] = c;
 
 		test(`shouldShowGoWelcomePage(${JSON.stringify(showVersions)}, ${newVersion}, ${oldVersion})`, () => {
-			assert.strictEqual(shouldShowGoWelcomePage(showVersions, newVersion, oldVersion), expected);
+			assert.strictEqual(hasNewsForNewVersion(showVersions, newVersion, oldVersion), expected);
 		});
 	});
 });