package.json: switch the main branch in preview mode

And, replace isNightly with isInPreviewMode. This allows us to enable
experimental features in our main branch. CI running on the release branch
should check the package.json preview bit isn't set.

Updates golang/vscode-go#961

Change-Id: I3d4b7230382e598c9e4cf05afec850760ce4e834
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/283640
Reviewed-by: Peter Weinberger <pjw@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/package.json b/package.json
index 28b3762..5fd3fa2 100644
--- a/package.json
+++ b/package.json
@@ -2,6 +2,7 @@
   "name": "go",
   "displayName": "Go",
   "version": "0.21.0-dev",
+  "preview": true,
   "publisher": "golang",
   "description": "Rich Go language support for Visual Studio Code",
   "author": {
diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts
index aa7b70d..b9ea67f 100644
--- a/src/goLanguageServer.ts
+++ b/src/goLanguageServer.ts
@@ -310,7 +310,7 @@
 	];
 
 	// Let gopls know about .tmpl - this is experimental, so enable it only in the experimental mode now.
-	if (isNightly()) {
+	if (isInPreviewMode()) {
 		documentSelector.push(
 			{ language: 'tmpl', scheme: 'file' },
 			{ language: 'tmpl', scheme: 'untitled' });
@@ -952,7 +952,7 @@
 	return time;
 };
 
-const acceptGoplsPrerelease = isNightly();
+const acceptGoplsPrerelease = isInPreviewMode();
 
 export const getLatestGoplsVersion = async (tool: Tool) => {
 	// If the user has a version of gopls that we understand,
@@ -1179,7 +1179,7 @@
 	// We then randomly pick a day in the rest of the month on which to prompt
 	// the user.
 	let probability = 0.01; // lower probability for the regular extension
-	if (isNightly()) {
+	if (isInPreviewMode()) {
 		probability = 0.0275;
 	}
 	cfg.promptThisMonth = Math.random() < probability;
@@ -1196,12 +1196,6 @@
 	return cfg;
 }
 
-// isNightly returns true if the extension ID is the extension ID for the
-// Nightly extension.
-export function isNightly(): boolean {
-	return extensionId === 'golang.go-nightly';
-}
-
 async function promptForSurvey(cfg: SurveyConfig, now: Date): Promise<SurveyConfig> {
 	const selected = await vscode.window.showInformationMessage(`Looks like you're using gopls, the Go language server.
 Would you be willing to fill out a quick survey about your experience with gopls?`, 'Yes', 'Not now', 'Never');
@@ -1604,13 +1598,22 @@
 }
 
 interface ExtensionInfo {
-	version: string;  // Extension version
+	version?: string;  // Extension version
 	appName: string;  // The application name of the editor, like 'VS Code'
+	isPreview?: boolean;  // if the extension runs in preview mode (e.g. Nightly)
 }
 
 function getExtensionInfo(): ExtensionInfo {
-	const version = vscode.extensions.getExtension(extensionId)?.packageJSON?.version;
+	const packageJSON = vscode.extensions.getExtension(extensionId)?.packageJSON;
+	const version = packageJSON?.version;
 	const appName = vscode.env.appName;
-	return { version, appName };
+	const isPreview = !!(packageJSON?.preview);
+	return { version, appName, isPreview };
+}
 
+// isInPreviewMode returns true if the extension's preview mode is set to true.
+// In the Nightly extension and the dev extension built from master, the preview
+// is set to true.
+export function isInPreviewMode(): boolean {
+	return getExtensionInfo().isPreview;
 }
diff --git a/src/goMain.ts b/src/goMain.ts
index a28fa41..8752c84 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -30,7 +30,7 @@
 	updateGoVarsFromConfig
 } from './goInstallTools';
 import {
-	isNightly,
+	isInPreviewMode,
 	languageServerIsRunning,
 	promptForLanguageServerDefaultChange,
 	resetSurveyConfig,
@@ -101,7 +101,7 @@
 		});
 	}
 
-	if (isNightly()) {
+	if (isInPreviewMode()) {
 		promptForLanguageServerDefaultChange(cfg);
 
 		// For Nightly extension users, show a message directing them to forums