Skip to content

Commit 08dacee

Browse files
committed
src/goStatus: assign id/name to each status bar item
Adopt the new `createStatusBarItem` API which allows users to control visibility per each status bar item the extension creates. This change also addresses an issue that caused the missing analysis tool error status overridden by the go version release notification message, because now the extension creates separate status bar items for these two different notifications. Fixes #1571 Change-Id: I6f457bace0385731a0218ccffebfba66e2fbb74b Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/370354 Reviewed-by: Suzy Mueller <[email protected]> Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]>
1 parent 8c3683f commit 08dacee

File tree

6 files changed

+56
-24
lines changed

6 files changed

+56
-24
lines changed

src/goCheck.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import { goVet } from './goVet';
2020
import { getTestFlags, goTest, TestConfig } from './testUtils';
2121
import { ICheckResult } from './util';
2222

23-
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
23+
const STATUS_BAR_ITEM_NAME = 'Go Test';
24+
const statusBarItem = vscode.window.createStatusBarItem(STATUS_BAR_ITEM_NAME, vscode.StatusBarAlignment.Left);
25+
statusBarItem.name = STATUS_BAR_ITEM_NAME;
2426
statusBarItem.command = 'go.test.showOutput';
2527
const neverAgain = { title: "Don't Show Again" };
2628

src/goEnvironmentStatus.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ export async function getLatestGoVersions(): Promise<GoEnvironmentOption[]> {
555555
return results;
556556
}
557557

558+
const STATUS_BAR_ITEM_NAME = 'Go Notification';
558559
const dismissedGoVersionUpdatesKey = 'dismissedGoVersionUpdates';
559560

560561
export async function offerToInstallLatestGoVersion() {
@@ -585,7 +586,12 @@ export async function offerToInstallLatestGoVersion() {
585586

586587
// notify user that there is a newer version of Go available
587588
if (options.length > 0) {
588-
addGoStatus('Go Update Available', 'go.promptforgoinstall', 'A newer version of Go is available');
589+
addGoStatus(
590+
STATUS_BAR_ITEM_NAME,
591+
'Go Update Available',
592+
'go.promptforgoinstall',
593+
'A newer version of Go is available'
594+
);
589595
vscode.commands.registerCommand('go.promptforgoinstall', () => {
590596
const download = {
591597
title: 'Download',
@@ -630,7 +636,7 @@ export async function offerToInstallLatestGoVersion() {
630636
// TODO: should we removeGoStatus if user has closed the notification
631637
// without any action? It's kind of a feature now - without selecting
632638
// neverAgain, user can hide this statusbar item.
633-
removeGoStatus();
639+
removeGoStatus(STATUS_BAR_ITEM_NAME);
634640
selection?.command();
635641
});
636642
});

src/goInstallTools.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import util = require('util');
4444
import vscode = require('vscode');
4545
import { isInPreviewMode, RestartReason } from './goLanguageServer';
4646

47+
const STATUS_BAR_ITEM_NAME = 'Go Tools';
48+
4749
// declinedUpdates tracks the tools that the user has declined to update.
4850
const declinedUpdates: Tool[] = [];
4951

@@ -395,7 +397,7 @@ Please select "Install", or follow the installation instructions [here](https://
395397
break;
396398
case 'Install All':
397399
await installTools(missing, goVersion);
398-
removeGoStatus();
400+
removeGoStatus(STATUS_BAR_ITEM_NAME);
399401
break;
400402
default:
401403
// The user has declined to install this tool.
@@ -555,12 +557,17 @@ export async function offerToInstallTools() {
555557
let missing = await getMissingTools(goVersion);
556558
missing = missing.filter((x) => x.isImportant);
557559
if (missing.length > 0) {
558-
addGoStatus('Analysis Tools Missing', 'go.promptforinstall', 'Not all Go tools are available on the GOPATH');
560+
addGoStatus(
561+
STATUS_BAR_ITEM_NAME,
562+
'Analysis Tools Missing',
563+
'go.promptforinstall',
564+
'Not all Go tools are available on the GOPATH'
565+
);
559566
vscode.commands.registerCommand('go.promptforinstall', () => {
560567
const installItem = {
561568
title: 'Install',
562569
async command() {
563-
removeGoStatus();
570+
removeGoStatus(STATUS_BAR_ITEM_NAME);
564571
await installTools(missing, goVersion);
565572
}
566573
};
@@ -583,7 +590,7 @@ export async function offerToInstallTools() {
583590
if (selection) {
584591
selection.command();
585592
} else {
586-
removeGoStatus();
593+
removeGoStatus(STATUS_BAR_ITEM_NAME);
587594
}
588595
});
589596
});

src/goMain.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,7 @@ import {
100100
resolvePath,
101101
runGoVersionM
102102
} from './util';
103-
import {
104-
clearCacheForTools,
105-
fileExists,
106-
getCurrentGoRoot,
107-
dirExists,
108-
setCurrentGoRoot,
109-
envPath
110-
} from './utils/pathUtils';
103+
import { clearCacheForTools, fileExists, getCurrentGoRoot, dirExists, envPath } from './utils/pathUtils';
111104
import { WelcomePanel } from './welcome';
112105
import semver = require('semver');
113106
import vscode = require('vscode');

src/goStatus.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ import { getGoVersion } from './util';
2424

2525
export const outputChannel = vscode.window.createOutputChannel('Go');
2626

27-
export const diagnosticsStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
27+
const STATUS_BAR_ITEM_NAME = 'Go Diagnostics';
28+
export const diagnosticsStatusBarItem = vscode.window.createStatusBarItem(
29+
STATUS_BAR_ITEM_NAME,
30+
vscode.StatusBarAlignment.Left
31+
);
32+
diagnosticsStatusBarItem.name = STATUS_BAR_ITEM_NAME;
2833

2934
// statusbar item for switching the Go environment
3035
export let goEnvStatusbarItem: vscode.StatusBarItem;
@@ -106,7 +111,13 @@ export async function expandGoStatusBar() {
106111
*/
107112
export async function initGoStatusBar() {
108113
if (!goEnvStatusbarItem) {
109-
goEnvStatusbarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 50);
114+
const STATUS_BAR_ITEM_NAME = 'Go';
115+
goEnvStatusbarItem = vscode.window.createStatusBarItem(
116+
STATUS_BAR_ITEM_NAME,
117+
vscode.StatusBarAlignment.Left,
118+
50
119+
);
120+
goEnvStatusbarItem.name = STATUS_BAR_ITEM_NAME;
110121
}
111122
// set Go version and command
112123
const version = await getGoVersion();
@@ -158,7 +169,13 @@ export function disposeGoStatusBar() {
158169
if (terminalCreationListener) {
159170
terminalCreationListener.dispose();
160171
}
161-
removeGoStatus();
172+
for (const statusBarEntry of statusBarEntries) {
173+
if (statusBarEntry) {
174+
const [name, entry] = statusBarEntry;
175+
statusBarEntries.delete(name);
176+
entry.dispose();
177+
}
178+
}
162179
}
163180

164181
/**
@@ -171,18 +188,23 @@ export function showGoStatusBar() {
171188
}
172189

173190
// status bar item to show warning messages such as missing analysis tools.
174-
let statusBarEntry: vscode.StatusBarItem;
191+
const statusBarEntries = new Map<string, vscode.StatusBarItem>();
175192

176-
export function removeGoStatus() {
193+
export function removeGoStatus(name: string) {
194+
const statusBarEntry = statusBarEntries.get(name);
177195
if (statusBarEntry) {
178196
statusBarEntry.dispose();
179-
statusBarEntry = undefined;
197+
statusBarEntries.delete(name);
180198
}
181199
}
182200

183-
export function addGoStatus(message: string, command: string, tooltip?: string) {
201+
export function addGoStatus(name: string, message: string, command: string, tooltip?: string) {
202+
let statusBarEntry = statusBarEntries.get(name);
184203
if (!statusBarEntry) {
185-
statusBarEntry = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, Number.MIN_VALUE);
204+
statusBarEntry = vscode.window.createStatusBarItem(name, vscode.StatusBarAlignment.Right, Number.MIN_VALUE);
205+
statusBarEntries.set(name, statusBarEntry);
206+
207+
statusBarEntry.name = name;
186208
}
187209
statusBarEntry.text = `$(alert) ${message}`;
188210
statusBarEntry.command = command;

src/testUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import { envPath, expandFilePathInOutput, getCurrentGoRoot, getCurrentGoWorkspac
2323
import { killProcessTree } from './utils/processUtils';
2424

2525
const testOutputChannel = vscode.window.createOutputChannel('Go Tests');
26-
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
26+
const STATUS_BAR_ITEM_NAME = 'Go Test Cancel';
27+
const statusBarItem = vscode.window.createStatusBarItem(STATUS_BAR_ITEM_NAME, vscode.StatusBarAlignment.Left);
28+
statusBarItem.name = STATUS_BAR_ITEM_NAME;
2729
statusBarItem.command = 'go.test.cancel';
2830
statusBarItem.text = '$(x) Cancel Running Tests';
2931

0 commit comments

Comments
 (0)