src/goMain.ts: show welcome page on update

When the user updates to a new Go version and we have specified
that version to automatically show the welcome page, the welcome
page will be displayed.

Change-Id: Ic8a2b20f7d3916f8e73fcdf92d3f4bf56f9cf944
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/283195
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/src/goMain.ts b/src/goMain.ts
index 8752c84..98d08bc 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -7,7 +7,9 @@
 'use strict';
 
 import * as path from 'path';
+import semver = require('semver');
 import vscode = require('vscode');
+import { extensionId } from './const';
 import { browsePackages } from './goBrowsePackage';
 import { buildCode } from './goBuild';
 import { check, notifyIfGeneratedFile, removeTestStatus } from './goCheck';
@@ -109,6 +111,9 @@
 		setTimeout(showGoNightlyWelcomeMessage, 10 * timeMinute);
 	}
 
+	// Show the Go welcome page on update.
+	showGoWelcomePage(ctx);
+
 	const configGOROOT = getGoConfig()['goroot'];
 	if (!!configGOROOT) {
 		logVerbose(`go.goroot = '${configGOROOT}'`);
@@ -562,6 +567,28 @@
 	});
 }
 
+function showGoWelcomePage(ctx: vscode.ExtensionContext) {
+	// Update this list of versions when there is a new version where we want to
+	// show the welcome page on update.
+	const showVersions: string[] = [];
+
+	let goExtensionVersionKey = 'go.extensionVersion';
+	if (isNightly()) {
+		goExtensionVersionKey = 'go.nightlyExtensionVersion';
+	}
+
+	const goExtension = vscode.extensions.getExtension(extensionId)!;
+	const goExtensionVersion = goExtension.packageJSON.version;
+	const savedGoExtensionVersion = getFromGlobalState(goExtensionVersionKey, '0.0.0');
+
+	if (semver.gt(semver.coerce(goExtensionVersion), semver.coerce(savedGoExtensionVersion))) {
+		updateGlobalState(goExtensionVersionKey, goExtensionVersion);
+		if (showVersions.includes(goExtensionVersion)) {
+			WelcomePanel.createOrShow(ctx.extensionUri);
+		}
+	}
+}
+
 async function showGoNightlyWelcomeMessage() {
 	const shown = getFromGlobalState(goNightlyPromptKey, false);
 	if (shown === true) {