Skip to content

Commit 3b5247e

Browse files
committed
Composite.create is sync
1 parent 2317de3 commit 3b5247e

14 files changed

Lines changed: 131 additions & 158 deletions

File tree

src/vs/workbench/browser/composite.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ export abstract class Composite extends Component implements IComposite {
9595
* Note that DOM-dependent calculations should be performed from the setVisible()
9696
* call. Only then the composite will be part of the DOM.
9797
*/
98-
create(parent: HTMLElement): Promise<void> {
98+
create(parent: HTMLElement): void {
9999
this.parent = parent;
100-
101-
return Promise.resolve(null);
102100
}
103101

104102
updateStyles(): void {

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

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ export abstract class CompositePart<T extends Composite> extends Part {
212212
// Remember
213213
this.lastActiveCompositeId = this.activeComposite.getId();
214214

215-
let createCompositePromise: TPromise<void>;
216-
217215
// Composites created for the first time
218216
let compositeContainer = this.mapCompositeToCompositeContainer[composite.getId()];
219217
if (!compositeContainer) {
@@ -223,92 +221,83 @@ export abstract class CompositePart<T extends Composite> extends Part {
223221
addClasses(compositeContainer, this.compositeCSSClass);
224222
compositeContainer.id = composite.getId();
225223

226-
createCompositePromise = composite.create(compositeContainer).then(() => {
227-
composite.updateStyles();
228-
});
224+
composite.create(compositeContainer);
225+
composite.updateStyles();
229226

230227
// Remember composite container
231228
this.mapCompositeToCompositeContainer[composite.getId()] = compositeContainer;
232229
}
233230

234-
// Composite already exists but is hidden
235-
else {
236-
createCompositePromise = Promise.resolve(null);
237-
}
238-
239231
// Report progress for slow loading composites (but only if we did not create the composites before already)
240232
const progressService = this.mapProgressServiceToComposite[composite.getId()];
241233
if (progressService && !compositeContainer) {
242-
this.mapProgressServiceToComposite[composite.getId()].showWhile(createCompositePromise, this.partService.isCreated() ? 800 : 3200 /* less ugly initial startup */);
234+
this.mapProgressServiceToComposite[composite.getId()].showWhile(Promise.resolve(), this.partService.isCreated() ? 800 : 3200 /* less ugly initial startup */);
243235
}
244236

245237
// Fill Content and Actions
246-
return createCompositePromise.then(() => {
247-
248-
// Make sure that the user meanwhile did not open another composite or closed the part containing the composite
249-
if (!this.activeComposite || composite.getId() !== this.activeComposite.getId()) {
250-
return void 0;
251-
}
238+
// Make sure that the user meanwhile did not open another composite or closed the part containing the composite
239+
if (!this.activeComposite || composite.getId() !== this.activeComposite.getId()) {
240+
return void 0;
241+
}
252242

253-
// Take Composite on-DOM and show
254-
this.getContentArea().appendChild(compositeContainer);
255-
show(compositeContainer);
243+
// Take Composite on-DOM and show
244+
this.getContentArea().appendChild(compositeContainer);
245+
show(compositeContainer);
256246

257-
// Setup action runner
258-
this.toolBar.actionRunner = composite.getActionRunner();
247+
// Setup action runner
248+
this.toolBar.actionRunner = composite.getActionRunner();
259249

260-
// Update title with composite title if it differs from descriptor
261-
const descriptor = this.registry.getComposite(composite.getId());
262-
if (descriptor && descriptor.name !== composite.getTitle()) {
263-
this.updateTitle(composite.getId(), composite.getTitle());
264-
}
250+
// Update title with composite title if it differs from descriptor
251+
const descriptor = this.registry.getComposite(composite.getId());
252+
if (descriptor && descriptor.name !== composite.getTitle()) {
253+
this.updateTitle(composite.getId(), composite.getTitle());
254+
}
265255

266-
// Handle Composite Actions
267-
let actionsBinding = this.mapActionsBindingToComposite[composite.getId()];
268-
if (!actionsBinding) {
269-
actionsBinding = this.collectCompositeActions(composite);
270-
this.mapActionsBindingToComposite[composite.getId()] = actionsBinding;
271-
}
272-
actionsBinding();
256+
// Handle Composite Actions
257+
let actionsBinding = this.mapActionsBindingToComposite[composite.getId()];
258+
if (!actionsBinding) {
259+
actionsBinding = this.collectCompositeActions(composite);
260+
this.mapActionsBindingToComposite[composite.getId()] = actionsBinding;
261+
}
262+
actionsBinding();
273263

274-
if (this.telemetryActionsListener) {
275-
this.telemetryActionsListener.dispose();
276-
this.telemetryActionsListener = null;
277-
}
264+
if (this.telemetryActionsListener) {
265+
this.telemetryActionsListener.dispose();
266+
this.telemetryActionsListener = null;
267+
}
278268

279-
// Action Run Handling
280-
this.telemetryActionsListener = this.toolBar.actionRunner.onDidRun(e => {
269+
// Action Run Handling
270+
this.telemetryActionsListener = this.toolBar.actionRunner.onDidRun(e => {
281271

282-
// Check for Error
283-
if (e.error && !errors.isPromiseCanceledError(e.error)) {
284-
this.notificationService.error(e.error);
285-
}
272+
// Check for Error
273+
if (e.error && !errors.isPromiseCanceledError(e.error)) {
274+
this.notificationService.error(e.error);
275+
}
286276

287-
// Log in telemetry
288-
if (this.telemetryService) {
289-
/* __GDPR__
290-
"workbenchActionExecuted" : {
291-
"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
292-
"from": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
293-
}
294-
*/
295-
this.telemetryService.publicLog('workbenchActionExecuted', { id: e.action.id, from: this.nameForTelemetry });
296-
}
297-
});
277+
// Log in telemetry
278+
if (this.telemetryService) {
279+
/* __GDPR__
280+
"workbenchActionExecuted" : {
281+
"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
282+
"from": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
283+
}
284+
*/
285+
this.telemetryService.publicLog('workbenchActionExecuted', { id: e.action.id, from: this.nameForTelemetry });
286+
}
287+
});
298288

299-
// Indicate to composite that it is now visible
300-
return composite.setVisible(true).then(() => {
289+
// Indicate to composite that it is now visible
290+
return composite.setVisible(true).then(() => {
301291

302-
// Make sure that the user meanwhile did not open another composite or closed the part containing the composite
303-
if (!this.activeComposite || composite.getId() !== this.activeComposite.getId()) {
304-
return;
305-
}
292+
// Make sure that the user meanwhile did not open another composite or closed the part containing the composite
293+
if (!this.activeComposite || composite.getId() !== this.activeComposite.getId()) {
294+
return;
295+
}
306296

307-
// Make sure the composite is layed out
308-
if (this.contentAreaSize) {
309-
composite.layout(this.contentAreaSize);
310-
}
311-
});
297+
// Make sure the composite is layed out
298+
if (this.contentAreaSize) {
299+
composite.layout(this.contentAreaSize);
300+
}
312301
}, error => this.onError(error));
313302
}
314303

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,11 @@ export abstract class BaseEditor extends Panel implements IEditor {
105105
this._options = options;
106106
}
107107

108-
create(parent: HTMLElement): void; // create is sync for editors
109-
create(parent: HTMLElement): Promise<void>;
110-
create(parent: HTMLElement): Promise<void> {
111-
const res = super.create(parent);
108+
create(parent: HTMLElement): void {
109+
super.create(parent);
112110

113111
// Create Editor
114112
this.createEditor(parent);
115-
116-
return res;
117113
}
118114

119115
/**
@@ -308,4 +304,4 @@ export class EditorMemento<T> implements IEditorMemento<T> {
308304
});
309305
});
310306
}
311-
}
307+
}

src/vs/workbench/browser/parts/views/panelViewlet.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,11 @@ export class PanelViewlet extends Viewlet {
211211
super(id, configurationService, partService, telemetryService, themeService, storageService);
212212
}
213213

214-
create(parent: HTMLElement): Promise<void> {
215-
return super.create(parent).then(() => {
216-
this.panelview = this._register(new PanelView(parent, this.options));
217-
this._register(this.panelview.onDidDrop(({ from, to }) => this.movePanel(from as ViewletPanel, to as ViewletPanel)));
218-
this._register(addDisposableListener(parent, EventType.CONTEXT_MENU, (e: MouseEvent) => this.showContextMenu(new StandardMouseEvent(e))));
219-
});
214+
create(parent: HTMLElement): void {
215+
super.create(parent);
216+
this.panelview = this._register(new PanelView(parent, this.options));
217+
this._register(this.panelview.onDidDrop(({ from, to }) => this.movePanel(from as ViewletPanel, to as ViewletPanel)));
218+
this._register(addDisposableListener(parent, EventType.CONTEXT_MENU, (e: MouseEvent) => this.showContextMenu(new StandardMouseEvent(e))));
220219
}
221220

222221
private showContextMenu(event: StandardMouseEvent): void {

src/vs/workbench/browser/parts/views/viewsViewlet.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,31 +143,30 @@ export abstract class ViewContainerViewlet extends PanelViewlet implements IView
143143
this._register(toDisposable(() => this.viewDisposables = dispose(this.viewDisposables)));
144144
}
145145

146-
create(parent: HTMLElement): Promise<void> {
147-
return super.create(parent).then(() => {
148-
this._register(this.onDidSashChange(() => this.saveViewSizes()));
149-
this.viewsModel.onDidAdd(added => this.onDidAddViews(added));
150-
this.viewsModel.onDidRemove(removed => this.onDidRemoveViews(removed));
151-
const addedViews: IAddedViewDescriptorRef[] = this.viewsModel.visibleViewDescriptors.map((viewDescriptor, index) => {
152-
const size = this.viewsModel.getSize(viewDescriptor.id);
153-
const collapsed = this.viewsModel.isCollapsed(viewDescriptor.id);
154-
return ({ viewDescriptor, index, size, collapsed });
155-
});
156-
if (addedViews.length) {
157-
this.onDidAddViews(addedViews);
158-
}
159-
160-
// Update headers after and title contributed views after available, since we read from cache in the beginning to know if the viewlet has single view or not. Ref #29609
161-
this.extensionService.whenInstalledExtensionsRegistered().then(() => {
162-
this.areExtensionsReady = true;
163-
if (this.panels.length) {
164-
this.updateTitleArea();
165-
this.updateViewHeaders();
166-
}
167-
});
146+
create(parent: HTMLElement): void {
147+
super.create(parent);
148+
this._register(this.onDidSashChange(() => this.saveViewSizes()));
149+
this.viewsModel.onDidAdd(added => this.onDidAddViews(added));
150+
this.viewsModel.onDidRemove(removed => this.onDidRemoveViews(removed));
151+
const addedViews: IAddedViewDescriptorRef[] = this.viewsModel.visibleViewDescriptors.map((viewDescriptor, index) => {
152+
const size = this.viewsModel.getSize(viewDescriptor.id);
153+
const collapsed = this.viewsModel.isCollapsed(viewDescriptor.id);
154+
return ({ viewDescriptor, index, size, collapsed });
155+
});
156+
if (addedViews.length) {
157+
this.onDidAddViews(addedViews);
158+
}
168159

169-
this.focus();
160+
// Update headers after and title contributed views after available, since we read from cache in the beginning to know if the viewlet has single view or not. Ref #29609
161+
this.extensionService.whenInstalledExtensionsRegistered().then(() => {
162+
this.areExtensionsReady = true;
163+
if (this.panels.length) {
164+
this.updateTitleArea();
165+
this.updateViewHeaders();
166+
}
170167
});
168+
169+
this.focus();
171170
}
172171

173172
getContextMenuActions(): IAction[] {

src/vs/workbench/parts/comments/electron-browser/commentsPanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class CommentsPanel extends Panel {
4949
super(COMMENTS_PANEL_ID, telemetryService, themeService, storageService);
5050
}
5151

52-
public create(parent: HTMLElement): Promise<void> {
52+
public create(parent: HTMLElement): void {
5353
super.create(parent);
5454

5555
dom.addClass(parent, 'comments-panel');
@@ -70,7 +70,7 @@ export class CommentsPanel extends Panel {
7070
this.applyStyles(styleElement);
7171
});
7272

73-
return this.render();
73+
this.render();
7474
}
7575

7676
private applyStyles(styleElement: HTMLStyleElement) {

src/vs/workbench/parts/debug/browser/debugViewlet.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ export class DebugViewlet extends ViewContainerViewlet {
6464
}));
6565
}
6666

67-
create(parent: HTMLElement): Promise<void> {
68-
return super.create(parent).then(() => {
69-
DOM.addClass(parent, 'debug-viewlet');
70-
});
67+
create(parent: HTMLElement): void {
68+
super.create(parent);
69+
DOM.addClass(parent, 'debug-viewlet');
7170
}
7271

7372
public focus(): void {

src/vs/workbench/parts/debug/electron-browser/repl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ export class Repl extends Panel implements IPrivateReplService, IHistoryNavigati
282282

283283
// --- Creation
284284

285-
async create(parent: HTMLElement): Promise<void> {
286-
await super.create(parent);
285+
create(parent: HTMLElement): void {
286+
super.create(parent);
287287
this.container = dom.append(parent, $('.repl'));
288288
this.treeContainer = dom.append(this.container, $('.repl-tree'));
289289
this.createReplInput(this.container);

src/vs/workbench/parts/extensions/electron-browser/extensionsViewlet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class ExtensionsViewlet extends ViewContainerViewlet implements IExtensio
325325
}, this, this.disposables);
326326
}
327327

328-
create(parent: HTMLElement): Promise<void> {
328+
create(parent: HTMLElement): void {
329329
addClass(parent, 'extensions-viewlet');
330330
this.root = parent;
331331

@@ -358,7 +358,7 @@ export class ExtensionsViewlet extends ViewContainerViewlet implements IExtensio
358358
this.searchBox.onShouldFocusResults(() => this.focusListView(), this, this.disposables);
359359

360360
this.extensionsBox = append(this.root, $('.extensions'));
361-
return super.create(this.extensionsBox);
361+
super.create(this.extensionsBox);
362362
}
363363

364364
setVisible(visible: boolean): Promise<void> {

src/vs/workbench/parts/files/electron-browser/explorerViewlet.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,9 @@ export class ExplorerViewlet extends ViewContainerViewlet implements IExplorerVi
175175
this._register(this.contextService.onDidChangeWorkspaceName(e => this.updateTitleArea()));
176176
}
177177

178-
create(parent: HTMLElement): Promise<void> {
179-
return super.create(parent).then(() => {
180-
DOM.addClass(parent, 'explorer-viewlet');
181-
});
178+
create(parent: HTMLElement): void {
179+
super.create(parent);
180+
DOM.addClass(parent, 'explorer-viewlet');
182181
}
183182

184183
protected createView(viewDescriptor: IViewDescriptor, options: IViewletViewOptions): ViewletPanel {

0 commit comments

Comments
 (0)