src/goStatus: avoid statusBarEntry leak

Reuse the existing status bar entry when addGoStatus is called multiple times
and set it undefined when dsposing it.

Change-Id: Ia39b8bf3c58d02135e442ee29f42201e2d02191f
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/282772
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/src/goStatus.ts b/src/goStatus.ts
index 5e30ede..2d0585e 100644
--- a/src/goStatus.ts
+++ b/src/goStatus.ts
@@ -21,7 +21,6 @@
 // statusbar item for switching the Go environment
 export let goEnvStatusbarItem: vscode.StatusBarItem;
 
-let statusBarEntry: vscode.StatusBarItem;
 let modulePath: string;
 export const languageServerIcon = '$(zap)';
 
@@ -146,14 +145,20 @@
 	}
 }
 
+// status bar item to show warning messages such as missing analysis tools.
+let statusBarEntry: vscode.StatusBarItem;
+
 export function removeGoStatus() {
 	if (statusBarEntry) {
 		statusBarEntry.dispose();
+		statusBarEntry = undefined;
 	}
 }
 
 export function addGoStatus(message: string, command: string, tooltip?: string) {
-	statusBarEntry = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, Number.MIN_VALUE);
+	if (!statusBarEntry) {
+		statusBarEntry = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, Number.MIN_VALUE);
+	}
 	statusBarEntry.text = `$(alert) ${message}`;
 	statusBarEntry.command = command;
 	statusBarEntry.tooltip = tooltip;