goLanguageServer.ts: allow Go Nightly to use pre-release versions.

Also add isForNightly that is true if the extension is for nightly

The extension name is one of the best way to check the extension's mode,
but I couldn't find a way to dynamically determine the
current extensionId through vscode api. For now I use the already existing
constant that happens to be in the telemetry.ts.
The extensionId is useful for purposes other than telemetry, so
we'd better consider refactoring in the future.

NIGHTLY ONLY

Change-Id: I00377edbca233d1951052d200c730001493dc3cd
diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts
index 56cc72f..5afa43f 100644
--- a/src/goLanguageServer.ts
+++ b/src/goLanguageServer.ts
@@ -47,7 +47,7 @@
 import { GoWorkspaceSymbolProvider } from './goSymbol';
 import { getTool, Tool } from './goTools';
 import { GoTypeDefinitionProvider } from './goTypeDefinition';
-import { getBinPath, getCurrentGoPath, getGoConfig, getToolsEnvVars } from './util';
+import { getBinPath, getCurrentGoPath, getGoConfig, getToolsEnvVars, isForNightly } from './util';
 
 interface LanguageServerConfig {
 	enabled: boolean;
@@ -401,8 +401,8 @@
 		return false;
 	}
 
-	// Get the latest gopls version.
-	let latestVersion = makeProxyCall ? await latestGopls(tool) : defaultLatestVersion;
+	// Get the latest gopls version. If it is for nightly, using the prereleased version is ok.
+	let latestVersion = makeProxyCall ? await latestGopls(tool, isForNightly) : defaultLatestVersion;
 
 	// If we failed to get the gopls version, pick the one we know to be latest at the time of this extension's last update
 	if (!latestVersion) {
@@ -477,7 +477,7 @@
 	return time;
 }
 
-async function latestGopls(tool: Tool): Promise<semver.SemVer> {
+async function latestGopls(tool: Tool, includePrerelease: boolean): Promise<semver.SemVer> {
 	// If the user has a version of gopls that we understand,
 	// ask the proxy for the latest version, and if the user's version is older,
 	// prompt them to update.
@@ -499,6 +499,9 @@
 	}
 	versions.sort(semver.rcompare);
 
+	if (includePrerelease) {
+		return versions[0];  // The first one in the prerelease.
+	}
 	// The first version in the sorted list without a prerelease tag.
 	return versions.find((version) => !version.prerelease || !version.prerelease.length);
 }
diff --git a/src/util.ts b/src/util.ts
index b61e51b..933b059 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -1052,3 +1052,6 @@
 	}
 	return false;
 }
+
+// isForNightly is true if the source code is built for a preview version of the extension.
+export const isForNightly: boolean = extensionId.endsWith('.go-nightly');