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

update EH side status bar info as new extensions are registered #183309

Merged
merged 1 commit into from
May 24, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/vs/workbench/api/browser/mainThreadStatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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 { StatusbarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar';
import { IStatusbarEntry, StatusbarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar';

@extHostNamedCustomer(MainContext.MainThreadStatusBar)
export class MainThreadStatusBar implements MainThreadStatusBarShape {
Expand All @@ -27,17 +27,27 @@ export class MainThreadStatusBar implements MainThreadStatusBarShape {
// once, at startup read existing items and send them over
const entries: StatusBarItemDto[] = [];
for (const [entryId, item] of statusbarService.getEntries()) {
entries.push({
entries.push(asDto(entryId, item));
}

proxy.$acceptStaticEntries(entries);

statusbarService.onDidChange(e => {
if (e.added) {
proxy.$acceptStaticEntries([asDto(e.added[0], e.added[1])]);
}
});

function asDto(entryId: string, item: { entry: IStatusbarEntry; alignment: StatusbarAlignment; priority: number }): StatusBarItemDto {
return {
entryId,
name: item.entry.name,
text: item.entry.text,
command: typeof item.entry.command === 'string' ? item.entry.command : undefined,
priority: item.priority,
alignLeft: item.alignment === StatusbarAlignment.LEFT
});
};
}

proxy.$acceptStaticEntries(entries);
}

dispose(): void {
Expand Down
25 changes: 23 additions & 2 deletions src/vs/workbench/api/browser/statusBarExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IAccessibilityInformation } from 'vs/platform/accessibility/common/acce
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { getCodiconAriaLabel } from 'vs/base/common/iconLabels';
import { hash } from 'vs/base/common/hash';
import { Event, Emitter } from 'vs/base/common/event';
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { Iterable } from 'vs/base/common/iterator';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
Expand All @@ -27,16 +28,24 @@ import { asStatusBarItemIdentifier } from 'vs/workbench/api/common/extHostTypes'
export const IExtensionStatusBarItemService = createDecorator<IExtensionStatusBarItemService>('IExtensionStatusBarItemService');

export interface IExtensionStatusBarItemChangeEvent {
readonly added?: Readonly<{ entryId: string } & IStatusbarEntry>;
readonly added?: ExtensionStatusBarEntry;
readonly removed?: string;
}

export type ExtensionStatusBarEntry = [string, {
entry: IStatusbarEntry;
alignment: MainThreadStatusBarAlignment;
priority: number;
}];

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): IDisposable;

getEntries(): Iterable<[string, { entry: IStatusbarEntry; alignment: MainThreadStatusBarAlignment; priority: number }]>;
getEntries(): Iterable<ExtensionStatusBarEntry>;
}


Expand All @@ -46,8 +55,17 @@ class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {

private readonly _entries: Map<string, { accessor: IStatusbarEntryAccessor; entry: IStatusbarEntry; alignment: MainThreadStatusBarAlignment; priority: number }> = new Map();

private readonly _onDidChange = new Emitter<IExtensionStatusBarItemChangeEvent>();
readonly onDidChange: Event<IExtensionStatusBarItemChangeEvent> = this._onDidChange.event;

constructor(@IStatusbarService private readonly _statusbarService: IStatusbarService) { }

dispose(): void {
this._entries.forEach(entry => entry.accessor.dispose());
this._entries.clear();
this._onDidChange.dispose();
}

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 {
// if there are icons in the text use the tooltip for the aria label
let ariaLabel: string;
Expand Down Expand Up @@ -98,6 +116,8 @@ class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {
priority
});

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

} else {
// Otherwise update
existingEntry.accessor.update(entry);
Expand All @@ -109,6 +129,7 @@ class ExtensionStatusBarItemService implements IExtensionStatusBarItemService {
if (entry) {
entry.accessor.dispose();
this._entries.delete(entryId);
this._onDidChange.fire({ removed: entryId });
}
});
}
Expand Down