Skip to content

Commit 35aa2b1

Browse files
authored
perf - work through workbench contributions (microsoft#203947) (microsoft#204350)
1 parent 212e24f commit 35aa2b1

File tree

15 files changed

+45
-101
lines changed

15 files changed

+45
-101
lines changed

src/vs/workbench/browser/parts/editor/editor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { GroupIdentifier, IWorkbenchEditorConfiguration, IEditorIdentifier, IEditorCloseEvent, IEditorPartOptions, IEditorPartOptionsChangeEvent, SideBySideEditor, EditorCloseContext, IEditorPane, IEditorPartLimitOptions, IEditorPartDecorationOptions } from 'vs/workbench/common/editor';
6+
import { GroupIdentifier, IWorkbenchEditorConfiguration, IEditorIdentifier, IEditorCloseEvent, IEditorPartOptions, IEditorPartOptionsChangeEvent, SideBySideEditor, EditorCloseContext, IEditorPane, IEditorPartLimitOptions, IEditorPartDecorationOptions, IEditorWillOpenEvent } from 'vs/workbench/common/editor';
77
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
88
import { IEditorGroup, GroupDirection, IMergeGroupOptions, GroupsOrder, GroupsArrangement, IAuxiliaryEditorPart, IEditorPart } from 'vs/workbench/services/editor/common/editorGroupsService';
99
import { IDisposable } from 'vs/base/common/lifecycle';
@@ -244,7 +244,9 @@ export interface IEditorGroupView extends IDisposable, ISerializableView, IEdito
244244

245245
readonly onDidFocus: Event<void>;
246246

247+
readonly onWillOpenEditor: Event<IEditorWillOpenEvent>;
247248
readonly onDidOpenEditorFail: Event<EditorInput>;
249+
248250
readonly onDidCloseEditor: Event<IEditorCloseEvent>;
249251

250252
readonly groupsView: IEditorGroupsView;

src/vs/workbench/common/contributions.ts

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { IdleDeadline, DeferredPromise, runWhenGlobalIdle } from 'vs/base/common
1010
import { mark } from 'vs/base/common/performance';
1111
import { ILogService } from 'vs/platform/log/common/log';
1212
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
13-
import { IFileService } from 'vs/platform/files/common/files';
1413
import { getOrSet } from 'vs/base/common/map';
1514
import { Disposable } from 'vs/base/common/lifecycle';
1615
import { IEditorPaneService } from 'vs/workbench/services/editor/common/editorPaneService';
@@ -67,14 +66,6 @@ export interface ILazyWorkbenchContributionInstantiation {
6766
readonly lazy: true;
6867
}
6968

70-
/**
71-
* A workbench contribution that will be instantiated when the
72-
* corresponding file system scheme is used.
73-
*/
74-
export interface IOnFilesystemWorkbenchContributionInstantiation {
75-
readonly scheme: string;
76-
}
77-
7869
/**
7970
* A workbench contribution that will be instantiated when the
8071
* corresponding editor is being created.
@@ -83,17 +74,12 @@ export interface IOnEditorWorkbenchContributionInstantiation {
8374
readonly editorTypeId: string;
8475
}
8576

86-
function isOnFilesystemWorkbenchContributionInstantiation(obj: unknown): obj is IOnFilesystemWorkbenchContributionInstantiation {
87-
const candidate = obj as IOnFilesystemWorkbenchContributionInstantiation | undefined;
88-
return !!candidate && typeof candidate.scheme === 'string';
89-
}
90-
9177
function isOnEditorWorkbenchContributionInstantiation(obj: unknown): obj is IOnEditorWorkbenchContributionInstantiation {
9278
const candidate = obj as IOnEditorWorkbenchContributionInstantiation | undefined;
9379
return !!candidate && typeof candidate.editorTypeId === 'string';
9480
}
9581

96-
export type WorkbenchContributionInstantiation = WorkbenchPhase | ILazyWorkbenchContributionInstantiation | IOnFilesystemWorkbenchContributionInstantiation | IOnEditorWorkbenchContributionInstantiation;
82+
export type WorkbenchContributionInstantiation = WorkbenchPhase | ILazyWorkbenchContributionInstantiation | IOnEditorWorkbenchContributionInstantiation;
9783

9884
function toWorkbenchPhase(phase: LifecyclePhase.Restored | LifecyclePhase.Eventually): WorkbenchPhase.AfterRestored | WorkbenchPhase.Eventually {
9985
switch (phase) {
@@ -160,11 +146,9 @@ export class WorkbenchContributionsRegistry extends Disposable implements IWorkb
160146
private lifecycleService: ILifecycleService | undefined;
161147
private logService: ILogService | undefined;
162148
private environmentService: IEnvironmentService | undefined;
163-
private fileService: IFileService | undefined;
164149
private editorPaneService: IEditorPaneService | undefined;
165150

166151
private readonly contributionsByPhase = new Map<LifecyclePhase, IWorkbenchContributionRegistration[]>();
167-
private readonly contributionsByFilesystem = new Map<string, IWorkbenchContributionRegistration[]>();
168152
private readonly contributionsByEditor = new Map<string, IWorkbenchContributionRegistration[]>();
169153
private readonly contributionsById = new Map<string, IWorkbenchContributionRegistration>();
170154

@@ -179,17 +163,15 @@ export class WorkbenchContributionsRegistry extends Disposable implements IWorkb
179163
registerWorkbenchContribution2(id: string, ctor: IConstructorSignature<IWorkbenchContribution>, phase: WorkbenchPhase.BlockStartup | WorkbenchPhase.BlockRestore): void;
180164
registerWorkbenchContribution2(id: string | undefined, ctor: IConstructorSignature<IWorkbenchContribution>, phase: WorkbenchPhase.AfterRestored | WorkbenchPhase.Eventually): void;
181165
registerWorkbenchContribution2(id: string, ctor: IConstructorSignature<IWorkbenchContribution>, lazy: ILazyWorkbenchContributionInstantiation): void;
182-
registerWorkbenchContribution2(id: string, ctor: IConstructorSignature<IWorkbenchContribution>, onFileSystem: IOnFilesystemWorkbenchContributionInstantiation): void;
183166
registerWorkbenchContribution2(id: string, ctor: IConstructorSignature<IWorkbenchContribution>, onEditor: IOnEditorWorkbenchContributionInstantiation): void;
184167
registerWorkbenchContribution2(id: string | undefined, ctor: IConstructorSignature<IWorkbenchContribution>, instantiation: WorkbenchContributionInstantiation): void {
185168
const contribution: IWorkbenchContributionRegistration = { id, ctor };
186169

187170
// Instantiate directly if we already have a matching instantiation condition
188171
if (
189-
this.instantiationService && this.lifecycleService && this.logService && this.environmentService && this.fileService && this.editorPaneService &&
172+
this.instantiationService && this.lifecycleService && this.logService && this.environmentService && this.editorPaneService &&
190173
(
191174
(typeof instantiation === 'number' && this.lifecycleService.phase >= instantiation) ||
192-
(typeof id === 'string' && isOnFilesystemWorkbenchContributionInstantiation(instantiation) && this.fileService.getProvider(instantiation.scheme)) ||
193175
(typeof id === 'string' && isOnEditorWorkbenchContributionInstantiation(instantiation) && this.editorPaneService.didInstantiateEditorPane(instantiation.editorTypeId))
194176
)
195177
) {
@@ -213,11 +195,6 @@ export class WorkbenchContributionsRegistry extends Disposable implements IWorkb
213195
console.error(`IWorkbenchContributionsRegistry#registerWorkbenchContribution(): Can't register multiple contributions with same id '${id}'`);
214196
}
215197

216-
// by filesystem
217-
if (isOnFilesystemWorkbenchContributionInstantiation(instantiation)) {
218-
getOrSet(this.contributionsByFilesystem, instantiation.scheme, []).push(contribution);
219-
}
220-
221198
// by editor
222199
if (isOnEditorWorkbenchContributionInstantiation(instantiation)) {
223200
getOrSet(this.contributionsByEditor, instantiation.editorTypeId, []).push(contribution);
@@ -267,22 +244,13 @@ export class WorkbenchContributionsRegistry extends Disposable implements IWorkb
267244
const lifecycleService = this.lifecycleService = accessor.get(ILifecycleService);
268245
const logService = this.logService = accessor.get(ILogService);
269246
const environmentService = this.environmentService = accessor.get(IEnvironmentService);
270-
const fileService = this.fileService = accessor.get(IFileService);
271247
const editorPaneService = this.editorPaneService = accessor.get(IEditorPaneService);
272248

273249
// Instantiate contributions by phase when they are ready
274250
for (const phase of [LifecyclePhase.Starting, LifecyclePhase.Ready, LifecyclePhase.Restored, LifecyclePhase.Eventually]) {
275251
this.instantiateByPhase(instantiationService, lifecycleService, logService, environmentService, phase);
276252
}
277253

278-
// Instantiate contributions by filesystem when they are activated or ready
279-
for (const scheme of this.contributionsByFilesystem.keys()) {
280-
if (fileService.getProvider(scheme)) {
281-
this.onFilesystem(scheme, instantiationService, lifecycleService, logService, environmentService);
282-
}
283-
}
284-
this._register(fileService.onWillActivateFileSystemProvider(e => this.onFilesystem(e.scheme, instantiationService, lifecycleService, logService, environmentService)));
285-
286254
// Instantiate contributions by editor when they are created or have been
287255
for (const editorTypeId of this.contributionsByEditor.keys()) {
288256
if (editorPaneService.didInstantiateEditorPane(editorTypeId)) {
@@ -292,17 +260,6 @@ export class WorkbenchContributionsRegistry extends Disposable implements IWorkb
292260
this._register(editorPaneService.onWillInstantiateEditorPane(e => this.onEditor(e.typeId, instantiationService, lifecycleService, logService, environmentService)));
293261
}
294262

295-
private onFilesystem(scheme: string, instantiationService: IInstantiationService, lifecycleService: ILifecycleService, logService: ILogService, environmentService: IEnvironmentService): void {
296-
const contributions = this.contributionsByFilesystem.get(scheme);
297-
if (contributions) {
298-
this.contributionsByFilesystem.delete(scheme);
299-
300-
for (const contribution of contributions) {
301-
this.safeCreateContribution(instantiationService, logService, environmentService, contribution, lifecycleService.phase);
302-
}
303-
}
304-
}
305-
306263
private onEditor(editorTypeId: string, instantiationService: IInstantiationService, lifecycleService: ILifecycleService, logService: ILogService, environmentService: IEnvironmentService): void {
307264
const contributions = this.contributionsByEditor.get(editorTypeId);
308265
if (contributions) {

src/vs/workbench/contrib/localHistory/browser/localHistory.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ import { WorkbenchPhase, registerWorkbenchContribution2 } from 'vs/workbench/com
88
import { LocalHistoryTimeline } from 'vs/workbench/contrib/localHistory/browser/localHistoryTimeline';
99

1010
// Register Local History Timeline
11-
registerWorkbenchContribution2(LocalHistoryTimeline.ID, LocalHistoryTimeline, WorkbenchPhase.BlockRestore);
11+
registerWorkbenchContribution2(LocalHistoryTimeline.ID, LocalHistoryTimeline, WorkbenchPhase.BlockRestore /* registrations only */);

src/vs/workbench/contrib/mergeEditor/browser/mergeEditor.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ Registry
9494
.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
9595
.registerWorkbenchContribution(MergeEditorOpenHandlerContribution, LifecyclePhase.Restored);
9696

97-
registerWorkbenchContribution2(MergeEditorResolverContribution.ID, MergeEditorResolverContribution, WorkbenchPhase.BlockStartup);
97+
registerWorkbenchContribution2(MergeEditorResolverContribution.ID, MergeEditorResolverContribution, WorkbenchPhase.BlockStartup /* only registers an editor resolver */);

src/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditor.contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Registry.as<IConfigurationRegistry>(Extensions.Configuration)
3636
registerSingleton(IMultiDiffSourceResolverService, MultiDiffSourceResolverService, InstantiationType.Delayed);
3737

3838
// Editor Integration
39-
registerWorkbenchContribution2(MultiDiffEditorResolverContribution.ID, MultiDiffEditorResolverContribution, WorkbenchPhase.BlockStartup);
39+
registerWorkbenchContribution2(MultiDiffEditorResolverContribution.ID, MultiDiffEditorResolverContribution, WorkbenchPhase.BlockStartup /* only registering an editor resolver */);
4040

4141
Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane)
4242
.registerEditorPane(
@@ -49,4 +49,4 @@ Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory)
4949

5050
// SCM integration
5151
registerAction2(OpenScmGroupAction);
52-
registerWorkbenchContribution2(ScmMultiDiffSourceResolverContribution.ID, ScmMultiDiffSourceResolverContribution, WorkbenchPhase.BlockStartup);
52+
registerWorkbenchContribution2(ScmMultiDiffSourceResolverContribution.ID, ScmMultiDiffSourceResolverContribution, WorkbenchPhase.BlockStartup /* only registering an editor resolver */);

src/vs/workbench/contrib/search/browser/replaceContributions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ import { WorkbenchPhase, registerWorkbenchContribution2 } from 'vs/workbench/com
99

1010
export function registerContributions(): void {
1111
registerSingleton(IReplaceService, ReplaceService, InstantiationType.Delayed);
12-
registerWorkbenchContribution2(ReplacePreviewContentProvider.ID, ReplacePreviewContentProvider, WorkbenchPhase.BlockStartup);
12+
registerWorkbenchContribution2(ReplacePreviewContentProvider.ID, ReplacePreviewContentProvider, WorkbenchPhase.BlockStartup /* registration only */);
1313
}

src/vs/workbench/contrib/url/browser/url.contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).regi
6666
registerWorkbenchContribution2(
6767
TrustedDomainsFileSystemProvider.ID,
6868
TrustedDomainsFileSystemProvider,
69-
WorkbenchPhase.BlockRestore
69+
WorkbenchPhase.BlockRestore // registration only
7070
);
7171
registerWorkbenchContribution2(
7272
ExternalUriResolverContribution.ID,
7373
ExternalUriResolverContribution,
74-
WorkbenchPhase.BlockRestore
74+
WorkbenchPhase.BlockRestore // registration only
7575
);
7676

7777

src/vs/workbench/contrib/webviewPanel/browser/webviewPanel.contribution.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Event } from 'vs/base/common/event';
76
import { Disposable } from 'vs/base/common/lifecycle';
87
import { localize } from 'vs/nls';
98
import { registerAction2 } from 'vs/platform/actions/common/actions';
@@ -20,6 +19,7 @@ import { WebviewEditor } from './webviewEditor';
2019
import { WebviewInput } from './webviewEditorInput';
2120
import { WebviewEditorInputSerializer } from './webviewEditorInputSerializer';
2221
import { IWebviewWorkbenchService, WebviewEditorService } from './webviewWorkbenchService';
22+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2323

2424
(Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane)).registerEditorPane(EditorPaneDescriptor.create(
2525
WebviewEditor,
@@ -32,25 +32,17 @@ class WebviewPanelContribution extends Disposable implements IWorkbenchContribut
3232
static readonly ID = 'workbench.contrib.webviewPanel';
3333

3434
constructor(
35-
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
35+
@IEditorService editorService: IEditorService,
36+
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService
3637
) {
3738
super();
3839

39-
// Add all the initial groups to be listened to
40-
this.editorGroupService.whenReady.then(() => this.editorGroupService.groups.forEach(group => {
41-
this.registerGroupListener(group);
40+
this._register(editorService.onWillOpenEditor(e => {
41+
const group = editorGroupService.getGroup(e.groupId);
42+
if (group) {
43+
this.onEditorOpening(e.editor, group);
44+
}
4245
}));
43-
44-
// Additional groups added should also be listened to
45-
this._register(this.editorGroupService.onDidAddGroup(group => this.registerGroupListener(group)));
46-
}
47-
48-
private registerGroupListener(group: IEditorGroup): void {
49-
const listener = group.onWillOpenEditor(e => this.onEditorOpening(e.editor, group));
50-
51-
Event.once(group.onWillDispose)(() => {
52-
listener.dispose();
53-
});
5446
}
5547

5648
private onEditorOpening(

src/vs/workbench/services/editor/browser/editorService.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
77
import { IResourceEditorInput, IEditorOptions, EditorActivation, IResourceEditorInputIdentifier, ITextResourceEditorInput } from 'vs/platform/editor/common/editor';
8-
import { SideBySideEditor, IEditorPane, GroupIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, EditorInputWithOptions, isEditorInputWithOptions, IEditorIdentifier, IEditorCloseEvent, ITextDiffEditorPane, IRevertOptions, SaveReason, EditorsOrder, IWorkbenchEditorConfiguration, EditorResourceAccessor, IVisibleEditorPane, EditorInputCapabilities, isResourceDiffEditorInput, IUntypedEditorInput, isResourceEditorInput, isEditorInput, isEditorInputWithOptionsAndGroup, IFindEditorOptions, isResourceMergeEditorInput } from 'vs/workbench/common/editor';
8+
import { SideBySideEditor, IEditorPane, GroupIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, EditorInputWithOptions, isEditorInputWithOptions, IEditorIdentifier, IEditorCloseEvent, ITextDiffEditorPane, IRevertOptions, SaveReason, EditorsOrder, IWorkbenchEditorConfiguration, EditorResourceAccessor, IVisibleEditorPane, EditorInputCapabilities, isResourceDiffEditorInput, IUntypedEditorInput, isResourceEditorInput, isEditorInput, isEditorInputWithOptionsAndGroup, IFindEditorOptions, isResourceMergeEditorInput, IEditorWillOpenEvent } from 'vs/workbench/common/editor';
99
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
1010
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
1111
import { ResourceMap, ResourceSet } from 'vs/base/common/map';
@@ -50,6 +50,9 @@ export class EditorService extends Disposable implements EditorServiceImpl {
5050
private readonly _onDidEditorsChange = this._register(new Emitter<IEditorsChangeEvent>());
5151
readonly onDidEditorsChange = this._onDidEditorsChange.event;
5252

53+
private readonly _onWillOpenEditor = this._register(new Emitter<IEditorWillOpenEvent>());
54+
readonly onWillOpenEditor = this._onWillOpenEditor.event;
55+
5356
private readonly _onDidCloseEditor = this._register(new Emitter<IEditorCloseEvent>());
5457
readonly onDidCloseEditor = this._onDidCloseEditor.event;
5558

@@ -169,6 +172,10 @@ export class EditorService extends Disposable implements EditorServiceImpl {
169172
this._onDidVisibleEditorsChange.fire();
170173
}));
171174

175+
groupDisposables.add(group.onWillOpenEditor(e => {
176+
this._onWillOpenEditor.fire(e);
177+
}));
178+
172179
groupDisposables.add(group.onDidCloseEditor(e => {
173180
this._onDidCloseEditor.fire(e);
174181
}));

src/vs/workbench/services/editor/common/editorGroupsService.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { Event } from 'vs/base/common/event';
77
import { IInstantiationService, createDecorator } from 'vs/platform/instantiation/common/instantiation';
8-
import { IEditorPane, GroupIdentifier, EditorInputWithOptions, CloseDirection, IEditorPartOptions, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, IEditorCloseEvent, IUntypedEditorInput, isEditorInput, IEditorWillMoveEvent, IEditorWillOpenEvent, IMatchEditorOptions, IActiveEditorChangeEvent, IFindEditorOptions, IToolbarActions } from 'vs/workbench/common/editor';
8+
import { IEditorPane, GroupIdentifier, EditorInputWithOptions, CloseDirection, IEditorPartOptions, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, IEditorCloseEvent, IUntypedEditorInput, isEditorInput, IEditorWillMoveEvent, IMatchEditorOptions, IActiveEditorChangeEvent, IFindEditorOptions, IToolbarActions } from 'vs/workbench/common/editor';
99
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
1010
import { IEditorOptions } from 'vs/platform/editor/common/editor';
1111
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -577,12 +577,6 @@ export interface IEditorGroup {
577577
*/
578578
readonly onWillMoveEditor: Event<IEditorWillMoveEvent>;
579579

580-
/**
581-
* An event that is fired when an editor is about to be opened
582-
* in the group.
583-
*/
584-
readonly onWillOpenEditor: Event<IEditorWillOpenEvent>;
585-
586580
/**
587581
* A unique identifier of this group that remains identical even if the
588582
* group is moved to different locations.

0 commit comments

Comments
 (0)