Skip to content

Commit

Permalink
StatusBar - keep disposing a status bar entry on the extension host s…
Browse files Browse the repository at this point in the history
…ide (#238453)

* StatusBar - keep disposing a status bar entry on the extension host side

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

Co-authored-by: Benjamin Pasero <[email protected]>

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

Co-authored-by: Benjamin Pasero <[email protected]>

* Fix argument names

---------

Co-authored-by: Benjamin Pasero <[email protected]>
  • Loading branch information
lszomoru and bpasero authored Jan 22, 2025
1 parent 23c4dc3 commit 4a3edfd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/vs/workbench/api/browser/mainThreadStatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export class MainThreadStatusBar implements MainThreadStatusBarShape {
this._proxy.$acceptStaticEntries(entries);

this._store.add(statusbarService.onDidChange(e => {
const added = e.added ? [asDto(e.added[0], e.added[1])] : [];
this._proxy.$acceptStaticEntries(added, e.removed);
if (e.added) {
this._proxy.$acceptStaticEntries([asDto(e.added[0], e.added[1])]);
}
}));

function asDto(entryId: string, item: { entry: IStatusbarEntry; alignment: StatusbarAlignment; priority: number }): StatusBarItemDto {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ export type StatusBarItemDto = {
};

export interface ExtHostStatusBarShape {
$acceptStaticEntries(added?: StatusBarItemDto[], removed?: string): void;
$acceptStaticEntries(added?: StatusBarItemDto[]): void;
$provideTooltip(entryId: string, cancellation: CancellationToken): Promise<string | IMarkdownString | undefined>;
}

Expand Down
15 changes: 6 additions & 9 deletions src/vs/workbench/api/common/extHostStatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export class ExtHostStatusBarEntry implements vscode.StatusBarItem {
private _timeoutHandle: any;
private _accessibilityInformation?: vscode.AccessibilityInformation;

constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, staticItems: ReadonlyMap<string, StatusBarItemDto>, extension: IExtensionDescription, id?: string, alignment?: ExtHostStatusBarAlignment, priority?: number);
constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, staticItems: ReadonlyMap<string, StatusBarItemDto>, extension: IExtensionDescription | undefined, id: string, alignment?: ExtHostStatusBarAlignment, priority?: number);
constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, staticItems: ReadonlyMap<string, StatusBarItemDto>, extension?: IExtensionDescription, id?: string, alignment: ExtHostStatusBarAlignment = ExtHostStatusBarAlignment.Left, priority?: number) {
constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, staticItems: ReadonlyMap<string, StatusBarItemDto>, extension: IExtensionDescription, id?: string, alignment?: ExtHostStatusBarAlignment, priority?: number, _onDispose?: () => void);
constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, staticItems: ReadonlyMap<string, StatusBarItemDto>, extension: IExtensionDescription | undefined, id: string, alignment?: ExtHostStatusBarAlignment, priority?: number, _onDispose?: () => void);
constructor(proxy: MainThreadStatusBarShape, commands: CommandsConverter, staticItems: ReadonlyMap<string, StatusBarItemDto>, extension?: IExtensionDescription, id?: string, alignment: ExtHostStatusBarAlignment = ExtHostStatusBarAlignment.Left, priority?: number, private _onDispose?: () => void) {
this.#proxy = proxy;
this.#commands = commands;

Expand Down Expand Up @@ -304,6 +304,7 @@ export class ExtHostStatusBarEntry implements vscode.StatusBarItem {

public dispose(): void {
this.hide();
this._onDispose?.();
this._disposed = true;
}
}
Expand Down Expand Up @@ -361,14 +362,10 @@ export class ExtHostStatusBar implements ExtHostStatusBarShape {
this._statusMessage = new StatusBarMessage(this);
}

$acceptStaticEntries(added: StatusBarItemDto[], removed?: string): void {
$acceptStaticEntries(added: StatusBarItemDto[]): void {
for (const item of added) {
this._existingItems.set(item.entryId, item);
}

if (removed) {
this._entries.delete(removed);
}
}

async $provideTooltip(entryId: string, cancellation: vscode.CancellationToken): Promise<string | htmlContent.IMarkdownString | undefined> {
Expand All @@ -384,7 +381,7 @@ export class ExtHostStatusBar implements ExtHostStatusBarShape {
createStatusBarEntry(extension: IExtensionDescription | undefined, id: string, alignment?: ExtHostStatusBarAlignment, priority?: number): vscode.StatusBarItem;
createStatusBarEntry(extension: IExtensionDescription, id?: string, alignment?: ExtHostStatusBarAlignment, priority?: number): vscode.StatusBarItem;
createStatusBarEntry(extension: IExtensionDescription, id: string, alignment?: ExtHostStatusBarAlignment, priority?: number): vscode.StatusBarItem {
const entry = new ExtHostStatusBarEntry(this._proxy, this._commands, this._existingItems, extension, id, alignment, priority);
const entry = new ExtHostStatusBarEntry(this._proxy, this._commands, this._existingItems, extension, id, alignment, priority, () => this._entries.delete(entry.entryId));
this._entries.set(entry.entryId, entry);

return entry;
Expand Down

0 comments on commit 4a3edfd

Please sign in to comment.