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

label: handle lazy formaters #57690

Merged
merged 3 commits into from
Sep 1, 2018
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
6 changes: 3 additions & 3 deletions src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import { serve as serveDriver } from 'vs/platform/driver/electron-main/driver';
import { IMenubarService } from 'vs/platform/menubar/common/menubar';
import { MenubarService } from 'vs/platform/menubar/electron-main/menubarService';
import { MenubarChannel } from 'vs/platform/menubar/node/menubarIpc';
import { ILabelService } from 'vs/platform/label/common/label';
import { ILabelService, RegisterFormatterEvent } from 'vs/platform/label/common/label';
import { CodeMenu } from 'vs/code/electron-main/menus';
import { hasArgs } from 'vs/platform/environment/node/argv';
import { RunOnceScheduler } from 'vs/base/common/async';
Expand Down Expand Up @@ -232,8 +232,8 @@ export class CodeApplication {
}
});

ipc.on('vscode:labelRegisterFormater', (event: any, { scheme, formater }) => {
this.labelService.registerFormatter(scheme, formater);
ipc.on('vscode:labelRegisterFormatter', (event: any, data: RegisterFormatterEvent) => {
this.labelService.registerFormatter(data.scheme, data.formatter);
});

ipc.on('vscode:toggleDevTools', (event: Event) => {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/editor/standalone/browser/simpleServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { WorkspaceEdit, isResourceTextEdit, TextEdit } from 'vs/editor/common/mo
import { IModelService } from 'vs/editor/common/services/modelService';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { localize } from 'vs/nls';
import { ILabelService, LabelRules } from 'vs/platform/label/common/label';
import { ILabelService, LabelRules, RegisterFormatterEvent } from 'vs/platform/label/common/label';

export class SimpleModel implements ITextEditorModel {

Expand Down Expand Up @@ -599,8 +599,8 @@ export class SimpleBulkEditService implements IBulkEditService {
export class SimpleUriLabelService implements ILabelService {
_serviceBrand: any;

private readonly _onDidRegisterFormatter: Emitter<{ scheme: string, formatter: LabelRules }> = new Emitter<{ scheme: string, formatter: LabelRules }>();
public readonly onDidRegisterFormatter: Event<{ scheme: string, formatter: LabelRules }> = this._onDidRegisterFormatter.event;
private readonly _onDidRegisterFormatter: Emitter<RegisterFormatterEvent> = new Emitter<RegisterFormatterEvent>();
public readonly onDidRegisterFormatter: Event<RegisterFormatterEvent> = this._onDidRegisterFormatter.event;

public getUriLabel(resource: URI, relative?: boolean): string {
if (resource.scheme === 'file') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class HistoryMainService implements IHistoryMainService {

private registerListeners(): void {
this.workspacesMainService.onWorkspaceSaved(e => this.onWorkspaceSaved(e));
this.labelService.onDidRegisterFormatter(() => this._onRecentlyOpenedChange.fire());
}

private onWorkspaceSaved(e: IWorkspaceSavedEvent): void {
Expand Down
11 changes: 8 additions & 3 deletions src/vs/platform/label/common/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ import { isParent } from 'vs/platform/files/common/files';
import { basename, dirname, join } from 'vs/base/common/paths';
import { Schemas } from 'vs/base/common/network';

export interface RegisterFormatterEvent {
scheme: string;
formatter: LabelRules;
}

export interface ILabelService {
_serviceBrand: any;
getUriLabel(resource: URI, relative?: boolean, forceNoTildify?: boolean): string;
getWorkspaceLabel(workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IWorkspace), options?: { verbose: boolean }): string;
registerFormatter(schema: string, formatter: LabelRules): IDisposable;
onDidRegisterFormatter: Event<{ scheme: string, formatter: LabelRules }>;
onDidRegisterFormatter: Event<RegisterFormatterEvent>;
}

export interface LabelRules {
Expand All @@ -51,14 +56,14 @@ export class LabelService implements ILabelService {
_serviceBrand: any;

private readonly formatters = new Map<string, LabelRules>();
private readonly _onDidRegisterFormatter = new Emitter<{ scheme: string, formatter: LabelRules }>();
private readonly _onDidRegisterFormatter = new Emitter<RegisterFormatterEvent>();

constructor(
@IEnvironmentService private environmentService: IEnvironmentService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) { }

get onDidRegisterFormatter(): Event<{ scheme: string, formatter: LabelRules }> {
get onDidRegisterFormatter(): Event<RegisterFormatterEvent> {
return this._onDidRegisterFormatter.event;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LabelRegistrationContribution implements IWorkbenchContribution {

constructor(@ILabelService labelService: ILabelService) {
labelService.onDidRegisterFormatter(data => {
ipc.send('vscode:labelRegisterFormater', data);
ipc.send('vscode:labelRegisterFormatter', data);
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/browser/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ export class ResourceLabel extends IconLabel {
return true; // same resource but different kind (file, folder)
}

if (newResource && this.computedPathLabel !== this.labelService.getUriLabel(newResource)) {
return true;
}

if (newResource && oldResource) {
return newResource.toString() !== oldResource.toString();
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class TitlebarPart extends Part implements ITitleService {
this._register(this.contextService.onDidChangeWorkspaceFolders(() => this.setTitle(this.getWindowTitle())));
this._register(this.contextService.onDidChangeWorkbenchState(() => this.setTitle(this.getWindowTitle())));
this._register(this.contextService.onDidChangeWorkspaceName(() => this.setTitle(this.getWindowTitle())));
this._register(this.labelService.onDidRegisterFormatter(() => this.setTitle(this.getWindowTitle())));
}

private onBlur(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
};

this.disposables.push(this.contextService.onDidChangeWorkspaceName(setHeader));
this.disposables.push(this.labelService.onDidRegisterFormatter(setHeader));
setHeader();
}

Expand Down Expand Up @@ -200,6 +201,10 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
this.disposables.push(this.contextService.onDidChangeWorkspaceFolders(e => this.refreshFromEvent(e.added)));
this.disposables.push(this.contextService.onDidChangeWorkbenchState(e => this.refreshFromEvent()));
this.disposables.push(this.fileService.onDidChangeFileSystemProviderRegistrations(() => this.refreshFromEvent()));
this.disposables.push(this.labelService.onDidRegisterFormatter(() => {
this._onDidChangeTitleArea.fire();
this.refreshFromEvent();
}));
}

layoutBody(size: number): void {
Expand Down