move ext host log chanel contribution to ext host starter

This commit is contained in:
Sandeep Somavarapu
2019-12-11 18:21:16 +01:00
parent e4162e3813
commit 201b5a2057
9 changed files with 45 additions and 141 deletions

View File

@@ -87,6 +87,7 @@ export interface IInitData {
telemetryInfo: ITelemetryInfo;
logLevel: LogLevel;
logsLocation: URI;
logFile: URI;
autoStart: boolean;
remote: { isRemote: boolean; authority: string | undefined; };
uiKind: UIKind;

View File

@@ -1,82 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { BrandedService, IInstantiationService, ServicesAccessor, IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation';
import { Registry } from 'vs/platform/registry/common/platform';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
/**
* An ext host contribution that will be loaded when the extension host starts and disposed when the extension host shuts down.
*/
export interface IExtHostContribution extends IDisposable {
// Marker Interface
}
export namespace Extensions {
export const ExtHost = 'exthost.contributions.kind';
}
type IExtHostContributionSignature<Service extends BrandedService[]> = new (...services: Service) => IExtHostContribution;
export interface IExtHostContributionsRegistry {
/**
* Registers a ext host contribution to the platform that will be loaded when the extension host starts and disposed when the extension host shuts down.
*/
registerExtHostContribution<Services extends BrandedService[]>(contribution: IExtHostContributionSignature<Services>): void;
/**
* Starts the registry by providing the required services.
*/
start(accessor: ServicesAccessor): void;
/**
* Stops the registry by disposing the instantiated contributions
*/
stop(): void;
}
class ExtHostContributionsRegistry implements IExtHostContributionsRegistry {
private instantiationService: IInstantiationService | undefined;
private readonly contributions: IConstructorSignature0<IExtHostContribution>[] = [];
private toBeInstantiated: IConstructorSignature0<IExtHostContribution>[] = [];
private instantiated: IExtHostContribution[] = [];
registerExtHostContribution<Services extends BrandedService[]>(ctor: { new(...services: Services): IExtHostContribution }): void {
this.contributions.push(ctor);
// Instantiate directly if started
if (this.instantiationService) {
this.instantiate(ctor);
}
// Otherwise keep contributions to be instantiated
else {
this.toBeInstantiated.push(ctor);
}
}
start(accessor: ServicesAccessor): void {
this.instantiationService = accessor.get(IInstantiationService);
this.toBeInstantiated.forEach(ctor => this.instantiate(ctor), this);
this.toBeInstantiated = [];
}
private instantiate<Services extends BrandedService[]>(ctor: { new(...services: Services): IExtHostContribution }) {
this.instantiated.push(this.instantiationService!.createInstance(ctor));
}
stop(): void {
this.instantiationService = undefined;
this.instantiated.forEach(dispose);
this.instantiated = [];
this.toBeInstantiated = [...this.contributions];
}
}
Registry.add(Extensions.ExtHost, new ExtHostContributionsRegistry());

View File

@@ -5,12 +5,10 @@
import { IInitData } from './extHost.protocol';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { URI } from 'vs/base/common/uri';
export const IExtHostInitDataService = createDecorator<IExtHostInitDataService>('IExtHostInitDataService');
export interface IExtHostInitDataService extends Readonly<IInitData> {
_serviceBrand: undefined;
readonly logFile: URI;
}