Skip to content

Commit 620a649

Browse files
committed
mark contributed status bar item as visible
1 parent 578b961 commit 620a649

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

src/vs/workbench/api/browser/mainThreadStatusBar.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ export class MainThreadStatusBar implements MainThreadStatusBarShape {
2828

2929
$setEntry(entryId: string, id: string, extensionId: string | undefined, name: string, text: string, tooltip: IMarkdownString | string | undefined, command: Command | undefined, color: string | ThemeColor | undefined, backgroundColor: string | ThemeColor | undefined, alignLeft: boolean, priority: number | undefined, accessibilityInformation: IAccessibilityInformation | undefined): void {
3030
const dispo = this.statusbarService.setOrUpdateEntry(entryId, id, extensionId, name, text, tooltip, command, color, backgroundColor, alignLeft, priority, accessibilityInformation);
31-
this.entries.set(entryId, dispo);
31+
if (!this.entries.has(entryId)) {
32+
this.entries.set(entryId, dispo);
33+
}
34+
}
35+
36+
async $hasEntry(entryId: string): Promise<boolean> {
37+
return this.statusbarService.hasEntry(entryId);
3238
}
3339

3440
$dispose(entryId: string) {

src/vs/workbench/api/browser/statusBarExtensionPoint.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ export interface IExtensionStatusBarItemService {
2929
readonly _serviceBrand: undefined;
3030

3131
setOrUpdateEntry(id: string, statusId: string, extensionId: string | undefined, name: string, text: string, tooltip: IMarkdownString | string | undefined, command: Command | undefined, color: string | ThemeColor | undefined, backgroundColor: string | ThemeColor | undefined, alignLeft: boolean, priority: number | undefined, accessibilityInformation: IAccessibilityInformation | undefined): IDisposable;
32+
33+
hasEntry(id: string): boolean;
3234
}
3335

3436

3537
class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {
3638

3739
declare readonly _serviceBrand: undefined;
3840

39-
private readonly entries: Map<string, { accessor: IStatusbarEntryAccessor; alignment: MainThreadStatusBarAlignment; priority: number }> = new Map();
41+
private readonly _entries: Map<string, { accessor: IStatusbarEntryAccessor; alignment: MainThreadStatusBarAlignment; priority: number }> = new Map();
4042

41-
constructor(
42-
@IStatusbarService private readonly _statusbarService: IStatusbarService
43-
) { }
43+
constructor(@IStatusbarService private readonly _statusbarService: IStatusbarService) { }
4444

4545
setOrUpdateEntry(entryId: string, id: string, extensionId: string | undefined, name: string, text: string, tooltip: IMarkdownString | string | undefined, command: Command | undefined, color: string | ThemeColor | undefined, backgroundColor: string | ThemeColor | undefined, alignLeft: boolean, priority: number | undefined, accessibilityInformation: IAccessibilityInformation | undefined): IDisposable {
4646
// if there are icons in the text use the tooltip for the aria label
@@ -65,7 +65,7 @@ class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {
6565
let alignment = alignLeft ? StatusbarAlignment.LEFT : StatusbarAlignment.RIGHT;
6666

6767
// alignment and priority can only be set once (at creation time)
68-
const existingEntry = this.entries.get(entryId);
68+
const existingEntry = this._entries.get(entryId);
6969
if (existingEntry) {
7070
alignment = existingEntry.alignment;
7171
priority = existingEntry.priority;
@@ -85,7 +85,7 @@ class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {
8585
entryPriority = priority;
8686
}
8787

88-
this.entries.set(entryId, {
88+
this._entries.set(entryId, {
8989
accessor: this._statusbarService.addEntry(entry, id, alignment, entryPriority),
9090
alignment,
9191
priority
@@ -97,13 +97,17 @@ class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {
9797
}
9898

9999
return toDisposable(() => {
100-
const entry = this.entries.get(entryId);
100+
const entry = this._entries.get(entryId);
101101
if (entry) {
102102
entry.accessor.dispose();
103-
this.entries.delete(entryId);
103+
this._entries.delete(entryId);
104104
}
105105
});
106106
}
107+
108+
hasEntry(id: string): boolean {
109+
return this._entries.has(id);
110+
}
107111
}
108112

109113
registerSingleton(IExtensionStatusBarItemService, ExtensionStatusBarItemService, InstantiationType.Delayed);

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ export interface MainThreadQuickOpenShape extends IDisposable {
609609
}
610610

611611
export interface MainThreadStatusBarShape extends IDisposable {
612+
$hasEntry(id: string): Promise<boolean>;
612613
$setEntry(id: string, statusId: string, extensionId: string | undefined, statusName: string, text: string, tooltip: IMarkdownString | string | undefined, command: ICommandDto | undefined, color: string | ThemeColor | undefined, backgroundColor: string | ThemeColor | undefined, alignLeft: boolean, priority: number | undefined, accessibilityInformation: IAccessibilityInformation | undefined): void;
613614
$dispose(id: string): void;
614615
}

src/vs/workbench/api/common/extHostStatusBar.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class ExtHostStatusBarEntry implements vscode.StatusBarItem {
3636
private _priority?: number;
3737

3838
private _disposed: boolean = false;
39-
private _visible: boolean = false;
39+
private _visible?: boolean;
4040

4141
private _text: string = '';
4242
private _tooltip?: string | vscode.MarkdownString;
@@ -59,9 +59,19 @@ export class ExtHostStatusBarEntry implements vscode.StatusBarItem {
5959
this.#proxy = proxy;
6060
this.#commands = commands;
6161

62-
this._entryId = id && extension
63-
? `${ExtensionIdentifier.toKey(extension.identifier)}.${id}`
64-
: String(ExtHostStatusBarEntry.ID_GEN++);
62+
if (id && extension) {
63+
this._entryId = `${ExtensionIdentifier.toKey(extension.identifier)}.${id}`;
64+
proxy.$hasEntry(this._entryId).then(exits => {
65+
if (exits && this._visible === undefined) {
66+
// mark new item as visible if it already exists
67+
// this can only happen when an item was contributed by an extension
68+
this._visible = true;
69+
this.update();
70+
}
71+
});
72+
} else {
73+
this._entryId = String(ExtHostStatusBarEntry.ID_GEN++);
74+
}
6575
this._extension = extension;
6676

6777
this._id = id;
@@ -259,8 +269,8 @@ export class ExtHostStatusBarEntry implements vscode.StatusBarItem {
259269

260270
class StatusBarMessage {
261271

262-
private _item: vscode.StatusBarItem;
263-
private _messages: { message: string }[] = [];
272+
private readonly _item: vscode.StatusBarItem;
273+
private readonly _messages: { message: string }[] = [];
264274

265275
constructor(statusBar: ExtHostStatusBar) {
266276
this._item = statusBar.createStatusBarEntry(undefined, 'status.extensionMessage', ExtHostStatusBarAlignment.Left, Number.MIN_VALUE);
@@ -300,7 +310,7 @@ export class ExtHostStatusBar {
300310

301311
private readonly _proxy: MainThreadStatusBarShape;
302312
private readonly _commands: CommandsConverter;
303-
private _statusMessage: StatusBarMessage;
313+
private readonly _statusMessage: StatusBarMessage;
304314

305315
constructor(mainContext: IMainContext, commands: CommandsConverter) {
306316
this._proxy = mainContext.getProxy(MainContext.MainThreadStatusBar);

0 commit comments

Comments
 (0)