Skip to content

Commit fee1599

Browse files
author
Loïc Mangeonjean
committed
feat: add customEditorRestore in layout options
1 parent a2aa88d commit fee1599

2 files changed

Lines changed: 112 additions & 2 deletions

File tree

src/service-override/workbench.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class CustomWorkbench extends Workbench {
4848
return this.instantiationService
4949
}
5050

51-
override restore(): void {
51+
override restore(instantiationService: IInstantiationService): void {
5252
try {
53-
this.restoreParts()
53+
this.restoreParts(instantiationService)
5454
} catch (error) {
5555
onUnexpectedError(error)
5656
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= <loic@coderpad.io>
3+
Date: Tue, 23 Sep 2025 11:13:34 +0200
4+
Subject: [PATCH] feat: add customEditorRestore
5+
6+
---
7+
src/vs/workbench/browser/layout.ts | 9 ++++++---
8+
src/vs/workbench/browser/workbench.ts | 12 +++++++-----
9+
2 files changed, 13 insertions(+), 8 deletions(-)
10+
11+
diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts
12+
index 89b39299fc6..1b4c53f1b08 100644
13+
--- a/src/vs/workbench/browser/layout.ts
14+
+++ b/src/vs/workbench/browser/layout.ts
15+
@@ -16,7 +16,7 @@ import { isTemporaryWorkspace, IWorkspaceContextService, WorkbenchState } from '
16+
import { IStorageService, StorageScope, StorageTarget } from '../../platform/storage/common/storage.js';
17+
import { IConfigurationChangeEvent, IConfigurationService, isConfigured } from '../../platform/configuration/common/configuration.js';
18+
import { ITitleService } from '../services/title/browser/titleService.js';
19+
-import { ServicesAccessor } from '../../platform/instantiation/common/instantiation.js';
20+
+import { IInstantiationService, ServicesAccessor } from '../../platform/instantiation/common/instantiation.js';
21+
import { StartupKind, ILifecycleService } from '../services/lifecycle/common/lifecycle.js';
22+
import { getMenuBarVisibility, IPath, hasNativeTitlebar, hasCustomTitlebar, TitleBarSetting, CustomTitleBarVisibility, useWindowControlsOverlay, DEFAULT_EMPTY_WINDOW_SIZE, DEFAULT_WORKSPACE_WINDOW_SIZE, hasNativeMenu, MenuSettings } from '../../platform/window/common/window.js';
23+
import { IHostService } from '../services/host/browser/host.js';
24+
@@ -299,7 +299,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
25+
26+
constructor(
27+
protected readonly parent: HTMLElement,
28+
- private readonly layoutOptions?: { resetLayout: boolean }
29+
+ private readonly layoutOptions?: { resetLayout?: boolean, customEditorRestore?: (accessor: ServicesAccessor, defaultLayout: boolean) => Promise<void> }
30+
) {
31+
super();
32+
33+
@@ -890,7 +890,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
34+
return this.restored;
35+
}
36+
37+
- protected restoreParts(): void {
38+
+ protected restoreParts(instantiationService: IInstantiationService): void {
39+
40+
// distinguish long running restore operations that
41+
// are required for the layout to be ready from those
42+
@@ -954,11 +954,14 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
43+
}));
44+
}
45+
46+
+ const customEditorRestorePromise = instantiationService.invokeFunction(this.layoutOptions?.customEditorRestore ?? (async () => { }), this.state.initialization.layout?.editors != null)
47+
+
48+
// do not block the overall layout ready flow from potentially
49+
// slow editors to resolve on startup
50+
layoutRestoredPromises.push(
51+
Promise.all([
52+
openEditorsPromise?.finally(() => mark('code/restoreEditors/editorsOpened')),
53+
+ customEditorRestorePromise?.finally(() => mark('code/restoreEditors/customEditorsOpened')),
54+
this.editorGroupService.whenRestored.finally(() => mark('code/restoreEditors/editorGroupsRestored'))
55+
]).finally(() => {
56+
// the `code/didRestoreEditors` perf mark is specifically
57+
diff --git a/src/vs/workbench/browser/workbench.ts b/src/vs/workbench/browser/workbench.ts
58+
index 591299041ab..3d1d703d927 100644
59+
--- a/src/vs/workbench/browser/workbench.ts
60+
+++ b/src/vs/workbench/browser/workbench.ts
61+
@@ -15,7 +15,7 @@ import { getSingletonServiceDescriptors } from '../../platform/instantiation/com
62+
import { Position, Parts, IWorkbenchLayoutService, positionToString } from '../services/layout/browser/layoutService.js';
63+
import { IStorageService, WillSaveStateReason, StorageScope, StorageTarget } from '../../platform/storage/common/storage.js';
64+
import { IConfigurationChangeEvent, IConfigurationService } from '../../platform/configuration/common/configuration.js';
65+
-import { IInstantiationService } from '../../platform/instantiation/common/instantiation.js';
66+
+import { IInstantiationService, ServicesAccessor } from '../../platform/instantiation/common/instantiation.js';
67+
import { ServiceCollection } from '../../platform/instantiation/common/serviceCollection.js';
68+
import { LifecyclePhase, ILifecycleService, WillShutdownEvent } from '../services/lifecycle/common/lifecycle.js';
69+
import { INotificationService } from '../../platform/notification/common/notification.js';
70+
@@ -53,6 +53,8 @@ export interface IWorkbenchOptions {
71+
* Whether to reset the workbench parts layout on startup.
72+
*/
73+
resetLayout?: boolean;
74+
+
75+
+ customEditorRestore?: (accessor: ServicesAccessor, defaultLayout: boolean) => Promise<void>
76+
}
77+
78+
export class Workbench extends Layout {
79+
@@ -69,7 +71,7 @@ export class Workbench extends Layout {
80+
private readonly serviceCollection: ServiceCollection,
81+
logService: ILogService
82+
) {
83+
- super(parent, { resetLayout: Boolean(options?.resetLayout) });
84+
+ super(parent, { resetLayout: options?.resetLayout, customEditorRestore: options?.customEditorRestore });
85+
86+
// Perf: measure workbench startup time
87+
mark('code/willStartWorkbench');
88+
@@ -150,7 +152,7 @@ export class Workbench extends Layout {
89+
this.layout();
90+
91+
// Restore
92+
- this.restore(lifecycleService);
93+
+ this.restore(instantiationService, lifecycleService);
94+
});
95+
96+
return instantiationService;
97+
@@ -378,11 +380,11 @@ export class Workbench extends Layout {
98+
});
99+
}
100+
101+
- protected restore(lifecycleService: ILifecycleService): void {
102+
+ protected restore(instantiationService: IInstantiationService, lifecycleService: ILifecycleService): void {
103+
104+
// Ask each part to restore
105+
try {
106+
- this.restoreParts();
107+
+ this.restoreParts(instantiationService);
108+
} catch (error) {
109+
onUnexpectedError(error);
110+
}

0 commit comments

Comments
 (0)