Merge from vscode 5b9869eb02fa4c96205a74d05cad9164dfd06d60 (#5607)

This commit is contained in:
Anthony Dresser
2019-05-24 12:20:30 -07:00
committed by GitHub
parent 361ada4963
commit bcc449b524
126 changed files with 3096 additions and 2255 deletions

View File

@@ -131,7 +131,7 @@ export class Workbench extends Layout {
// Services
const instantiationService = this.initServices(this.serviceCollection);
instantiationService.invokeFunction(accessor => {
instantiationService.invokeFunction(async accessor => {
const lifecycleService = accessor.get(ILifecycleService);
const storageService = accessor.get(IStorageService);
const configurationService = accessor.get(IConfigurationService);
@@ -158,7 +158,11 @@ export class Workbench extends Layout {
this.layout();
// Restore
this.restoreWorkbench(accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IViewletService), accessor.get(IPanelService), accessor.get(ILogService), lifecycleService).then(undefined, error => onUnexpectedError(error));
try {
await this.restoreWorkbench(accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IViewletService), accessor.get(IPanelService), accessor.get(ILogService), lifecycleService);
} catch (error) {
onUnexpectedError(error);
}
});
return instantiationService;
@@ -338,7 +342,7 @@ export class Workbench extends Layout {
registerNotificationCommands(notificationsCenter, notificationsToasts);
}
private restoreWorkbench(
private async restoreWorkbench(
editorService: IEditorService,
editorGroupService: IEditorGroupsService,
viewletService: IViewletService,
@@ -349,36 +353,39 @@ export class Workbench extends Layout {
const restorePromises: Promise<void>[] = [];
// Restore editors
mark('willRestoreEditors');
restorePromises.push(editorGroupService.whenRestored.then(() => {
restorePromises.push((async () => {
mark('willRestoreEditors');
function openEditors(editors: IResourceEditor[], editorService: IEditorService) {
if (editors.length) {
return editorService.openEditors(editors);
}
return Promise.resolve(undefined);
}
// first ensure the editor part is restored
await editorGroupService.whenRestored;
// then see for editors to open as instructed
let editors: IResourceEditor[];
if (Array.isArray(this.state.editor.editorsToOpen)) {
return openEditors(this.state.editor.editorsToOpen, editorService);
editors = this.state.editor.editorsToOpen;
} else {
editors = await this.state.editor.editorsToOpen;
}
return this.state.editor.editorsToOpen.then(editors => openEditors(editors, editorService));
}).then(() => mark('didRestoreEditors')));
if (editors.length) {
await editorService.openEditors(editors);
}
mark('didRestoreEditors');
})());
// Restore Sidebar
if (this.state.sideBar.viewletToRestore) {
mark('willRestoreViewlet');
restorePromises.push(viewletService.openViewlet(this.state.sideBar.viewletToRestore)
.then(viewlet => {
if (!viewlet) {
return viewletService.openViewlet(viewletService.getDefaultViewletId()); // fallback to default viewlet as needed
}
restorePromises.push((async () => {
mark('willRestoreViewlet');
return viewlet;
})
.then(() => mark('didRestoreViewlet')));
const viewlet = await viewletService.openViewlet(this.state.sideBar.viewletToRestore);
if (!viewlet) {
await viewletService.openViewlet(viewletService.getDefaultViewletId()); // fallback to default viewlet as needed
}
mark('didRestoreViewlet');
})());
}
// Restore Panel
@@ -401,23 +408,24 @@ export class Workbench extends Layout {
// Emit a warning after 10s if restore does not complete
const restoreTimeoutHandle = setTimeout(() => logService.warn('Workbench did not finish loading in 10 seconds, that might be a problem that should be reported.'), 10000);
return Promise.all(restorePromises)
.then(() => clearTimeout(restoreTimeoutHandle))
.catch(error => onUnexpectedError(error))
.finally(() => {
try {
await Promise.all(restorePromises);
// Set lifecycle phase to `Restored`
lifecycleService.phase = LifecyclePhase.Restored;
clearTimeout(restoreTimeoutHandle);
} catch (error) {
onUnexpectedError(error);
} finally {
// Set lifecycle phase to `Eventually` after a short delay and when idle (min 2.5sec, max 5sec)
setTimeout(() => {
this._register(runWhenIdle(() => {
lifecycleService.phase = LifecyclePhase.Eventually;
}, 2500));
}, 2500);
// Set lifecycle phase to `Restored`
lifecycleService.phase = LifecyclePhase.Restored;
// Telemetry: startup metrics
mark('didStartWorkbench');
});
// Set lifecycle phase to `Eventually` after a short delay and when idle (min 2.5sec, max 5sec)
setTimeout(() => {
this._register(runWhenIdle(() => lifecycleService.phase = LifecyclePhase.Eventually, 2500));
}, 2500);
// Telemetry: startup metrics
mark('didStartWorkbench');
}
}
}