Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispose status bar items on EH restart, but only those that were defined by extensions, not those defined statically #186479

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/vs/workbench/api/browser/mainThreadStatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import { MainThreadStatusBarShape, MainContext, ExtHostContext, StatusBarItemDto } from '../common/extHost.protocol';
import { ThemeColor } from 'vs/base/common/themables';
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { Command } from 'vs/editor/common/languages';
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { IExtensionStatusBarItemService } from 'vs/workbench/api/browser/statusBarExtensionPoint';
import { IExtensionStatusBarItemService, StatusBarUpdateKind } from 'vs/workbench/api/browser/statusBarExtensionPoint';
import { IStatusbarEntry, StatusbarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar';

@extHostNamedCustomer(MainContext.MainThreadStatusBar)
Expand Down Expand Up @@ -57,7 +57,10 @@ export class MainThreadStatusBar implements MainThreadStatusBarShape {
}

$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 {
this.statusbarService.setOrUpdateEntry(entryId, id, extensionId, name, text, tooltip, command, color, backgroundColor, alignLeft, priority, accessibilityInformation);
const kind = this.statusbarService.setOrUpdateEntry(entryId, id, extensionId, name, text, tooltip, command, color, backgroundColor, alignLeft, priority, accessibilityInformation);
if (kind === StatusBarUpdateKind.DidDefine) {
this._store.add(toDisposable(() => this.statusbarService.unsetEntry(entryId)));
}
}

$disposeEntry(entryId: string) {
Expand Down
18 changes: 14 additions & 4 deletions src/vs/workbench/api/browser/statusBarExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ export type ExtensionStatusBarEntry = [string, {
priority: number;
}];

export const enum StatusBarUpdateKind {
DidDefine,
DidUpdate
}

export interface IExtensionStatusBarItemService {
readonly _serviceBrand: undefined;

onDidChange: Event<IExtensionStatusBarItemChangeEvent>;

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): void;
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): StatusBarUpdateKind;

unsetEntry(id: string): void;

Expand Down Expand Up @@ -72,7 +77,7 @@ class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {
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 {
): StatusBarUpdateKind {
// if there are icons in the text use the tooltip for the aria label
let ariaLabel: string;
let role: string | undefined = undefined;
Expand Down Expand Up @@ -129,16 +134,19 @@ class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {
});

this._onDidChange.fire({ added: [entryId, { entry, alignment, priority }] });
return StatusBarUpdateKind.DidDefine;

} else {
// Otherwise update
existingEntry.accessor.update(entry);
existingEntry.entry = entry;
return StatusBarUpdateKind.DidUpdate;
}
}

unsetEntry(entryId: string): void {
this._entries.get(entryId)?.disposable.dispose();
this._entries.delete(entryId);
}

getEntries(): Iterable<[string, { entry: IStatusbarEntry; alignment: MainThreadStatusBarAlignment; priority: number }]> {
Expand Down Expand Up @@ -267,7 +275,7 @@ export class StatusBarItemsExtensionPoint {

const fullItemId = asStatusBarItemIdentifier(entry.description.identifier, candidate.id);

statusBarItemsService.setOrUpdateEntry(
const kind = statusBarItemsService.setOrUpdateEntry(
fullItemId,
fullItemId,
ExtensionIdentifier.toKey(entry.description.identifier),
Expand All @@ -281,7 +289,9 @@ export class StatusBarItemsExtensionPoint {
candidate.accessibilityInformation
);

contributions.add(toDisposable(() => statusBarItemsService.unsetEntry(fullItemId)));
if (kind === StatusBarUpdateKind.DidDefine) {
contributions.add(toDisposable(() => statusBarItemsService.unsetEntry(fullItemId)));
}
}
}
});
Expand Down