From a087d3531e0984708f779b5114d85f3924af97b3 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 24 Sep 2018 14:55:52 +0200 Subject: [PATCH] merge configuration registries again, don't use whenIdle for contributions --- src/vs/workbench/browser/contributions.ts | 93 ----------------------- src/vs/workbench/common/contributions.ts | 65 ++++++++++++++++ src/vs/workbench/workbench.main.ts | 3 - 3 files changed, 65 insertions(+), 96 deletions(-) delete mode 100644 src/vs/workbench/browser/contributions.ts diff --git a/src/vs/workbench/browser/contributions.ts b/src/vs/workbench/browser/contributions.ts deleted file mode 100644 index 4d810eb863e..00000000000 --- a/src/vs/workbench/browser/contributions.ts +++ /dev/null @@ -1,93 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -'use strict'; - -import { Registry } from 'vs/platform/registry/common/platform'; -import { IInstantiationService, IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation'; -import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; -import { runWhenIdle, IdleDeadline } from 'vs/base/browser/browser'; -import { IWorkbenchContributionsRegistry, IWorkbenchContribution, IWorkbenchContributionSignature, Extensions } from 'vs/workbench/common/contributions'; - -class WorkbenchContributionsRegistry implements IWorkbenchContributionsRegistry { - private instantiationService: IInstantiationService; - private lifecycleService: ILifecycleService; - - private toBeInstantiated: Map[]> = new Map[]>(); - - registerWorkbenchContribution(ctor: IWorkbenchContributionSignature, phase: LifecyclePhase = LifecyclePhase.Starting): void { - - // Instantiate directly if we are already matching the provided phase - if (this.instantiationService && this.lifecycleService && this.lifecycleService.phase >= phase) { - this.instantiationService.createInstance(ctor); - } - - // Otherwise keep contributions by lifecycle phase - else { - let toBeInstantiated = this.toBeInstantiated.get(phase); - if (!toBeInstantiated) { - toBeInstantiated = []; - this.toBeInstantiated.set(phase, toBeInstantiated); - } - - toBeInstantiated.push(ctor); - } - } - - start(instantiationService: IInstantiationService, lifecycleService: ILifecycleService): void { - this.instantiationService = instantiationService; - this.lifecycleService = lifecycleService; - - [LifecyclePhase.Starting, LifecyclePhase.Restoring, LifecyclePhase.Running, LifecyclePhase.Eventually].forEach(phase => { - this.instantiateByPhase(instantiationService, lifecycleService, phase); - }); - } - - private instantiateByPhase(instantiationService: IInstantiationService, lifecycleService: ILifecycleService, phase: LifecyclePhase): void { - - // Instantiate contributions directly when phase is already reached - if (lifecycleService.phase >= phase) { - this.doInstantiateByPhase(instantiationService, phase); - } - - // Otherwise wait for phase to be reached - else { - lifecycleService.when(phase).then(() => { - this.doInstantiateByPhase(instantiationService, phase); - }); - } - } - - private doInstantiateByPhase(instantiationService: IInstantiationService, phase: LifecyclePhase): void { - const toBeInstantiated = this.toBeInstantiated.get(phase); - if (!toBeInstantiated) { - return; - } - if (phase !== LifecyclePhase.Eventually) { - // instantiate every synchronously and blocking - for (const ctor of toBeInstantiated) { - instantiationService.createInstance(ctor); - } - } else { - // for the Eventually-phase we instantiate contributions - // only when idle. this might take a few idle-busy-cycles - // but will finish within one second - let i = 0; - const instantiateSome = (idle: IdleDeadline) => { - while (i < toBeInstantiated.length) { - const ctor = toBeInstantiated[i++]; - instantiationService.createInstance(ctor); - if (idle.timeRemaining() < 1) { - // time is up -> reschedule - runWhenIdle(instantiateSome, 1000); - break; - } - } - }; - runWhenIdle(instantiateSome, 1000); - } - } -} - -Registry.add(Extensions.Workbench, new WorkbenchContributionsRegistry()); diff --git a/src/vs/workbench/common/contributions.ts b/src/vs/workbench/common/contributions.ts index 2ae0bbec1d4..b48d2e6fab3 100644 --- a/src/vs/workbench/common/contributions.ts +++ b/src/vs/workbench/common/contributions.ts @@ -7,6 +7,7 @@ import { IInstantiationService, IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation'; import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; +import { Registry } from 'vs/platform/registry/common/platform'; // --- Workbench Contribution Registry @@ -38,3 +39,67 @@ export interface IWorkbenchContributionsRegistry { */ start(instantiationService: IInstantiationService, lifecycleService: ILifecycleService): void; } + + +class WorkbenchContributionsRegistry implements IWorkbenchContributionsRegistry { + private instantiationService: IInstantiationService; + private lifecycleService: ILifecycleService; + + private toBeInstantiated: Map[]> = new Map[]>(); + + registerWorkbenchContribution(ctor: IWorkbenchContributionSignature, phase: LifecyclePhase = LifecyclePhase.Starting): void { + + // Instantiate directly if we are already matching the provided phase + if (this.instantiationService && this.lifecycleService && this.lifecycleService.phase >= phase) { + this.instantiationService.createInstance(ctor); + } + + // Otherwise keep contributions by lifecycle phase + else { + let toBeInstantiated = this.toBeInstantiated.get(phase); + if (!toBeInstantiated) { + toBeInstantiated = []; + this.toBeInstantiated.set(phase, toBeInstantiated); + } + + toBeInstantiated.push(ctor); + } + } + + start(instantiationService: IInstantiationService, lifecycleService: ILifecycleService): void { + this.instantiationService = instantiationService; + this.lifecycleService = lifecycleService; + + [LifecyclePhase.Starting, LifecyclePhase.Restoring, LifecyclePhase.Running, LifecyclePhase.Eventually].forEach(phase => { + this.instantiateByPhase(instantiationService, lifecycleService, phase); + }); + } + + private instantiateByPhase(instantiationService: IInstantiationService, lifecycleService: ILifecycleService, phase: LifecyclePhase): void { + + // Instantiate contributions directly when phase is already reached + if (lifecycleService.phase >= phase) { + this.doInstantiateByPhase(instantiationService, phase); + } + + // Otherwise wait for phase to be reached + else { + lifecycleService.when(phase).then(() => { + this.doInstantiateByPhase(instantiationService, phase); + }); + } + } + + private doInstantiateByPhase(instantiationService: IInstantiationService, phase: LifecyclePhase): void { + const toBeInstantiated = this.toBeInstantiated.get(phase); + if (toBeInstantiated) { + // instantiate everything synchronously and blocking + for (const ctor of toBeInstantiated) { + instantiationService.createInstance(ctor); + } + this.toBeInstantiated.delete(phase); + } + } +} + +Registry.add(Extensions.Workbench, new WorkbenchContributionsRegistry()); diff --git a/src/vs/workbench/workbench.main.ts b/src/vs/workbench/workbench.main.ts index 0323cd30344..ce9193eb9cf 100644 --- a/src/vs/workbench/workbench.main.ts +++ b/src/vs/workbench/workbench.main.ts @@ -9,9 +9,6 @@ import 'vs/base/common/strings'; import 'vs/base/common/errors'; -// contributions logic -import 'vs/workbench/browser/contributions'; - // Configuration import 'vs/workbench/services/configuration/common/configurationExtensionPoint'; -- GitLab