goLanguageServer: add extra information to automated error reports

Keep track of the total number of times the language server has been
started and how many times it has been manually restarted by the user.
Total start count will account for the first start + any automated
restarts + any manual restarts.

Also, add the initialization to the automated error report.

Change-Id: If10b65a27d362dbf9a7c7815623670fbfdf6a360
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/287952
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts
index 2c3a109..77e2195 100644
--- a/src/goLanguageServer.ts
+++ b/src/goLanguageServer.ts
@@ -95,6 +95,10 @@
 let serverTraceChannel: vscode.OutputChannel;
 let crashCount = 0;
 
+// Some metrics for automated issue reports:
+let manualRestartCount = 0;
+let totalStartCount = 0;
+
 // defaultLanguageProviders is the list of providers currently registered.
 let defaultLanguageProviders: vscode.Disposable[] = [];
 
@@ -235,6 +239,8 @@
 			await suggestGoplsIssueReport(
 				`Looks like you're about to manually restart the language server.`,
 				errorKind.manualRestart);
+
+			manualRestartCount++;
 			restartLanguageServer();
 		});
 		ctx.subscriptions.push(restartCommand);
@@ -245,6 +251,7 @@
 	disposeDefaultProviders();
 
 	languageServerDisposable = languageClient.start();
+	totalStartCount++;
 	ctx.subscriptions.push(languageServerDisposable);
 	return true;
 }
@@ -323,7 +330,7 @@
 				vscode.window.showErrorMessage(
 					`The language server is not able to serve any features. Initialization failed: ${error}. `
 				);
-				suggestGoplsIssueReport(`The gopls server failed to initialize.`, errorKind.initializationFailure);
+				suggestGoplsIssueReport(`The gopls server failed to initialize`, errorKind.initializationFailure, error);
 				return false;
 			},
 			errorHandler: {
@@ -1272,7 +1279,7 @@
 }
 
 // suggestGoplsIssueReport prompts users to file an issue with gopls.
-async function suggestGoplsIssueReport(msg: string, reason: errorKind) {
+async function suggestGoplsIssueReport(msg: string, reason: errorKind, initializationError?: WebRequest.ResponseError<InitializeError>) {
 	// Don't prompt users who manually restart to file issues until gopls/v1.0.
 	if (reason === errorKind.manualRestart) {
 		return;
@@ -1348,6 +1355,9 @@
 gopls flags: ${settings}
 extension version: ${extInfo.version}
 environment: ${extInfo.appName}
+initialization error: ${initializationError}
+manual restart count: ${manualRestartCount}
+total start count: ${totalStartCount}
 
 ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.