From a2a48e3ba8a6c98bc5e9b423e74fd60100eb7235 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 1 Mar 2016 12:13:02 +0100 Subject: [PATCH] Simplify IExtensionService --- .../browser/standalone/simpleServices.ts | 4 --- .../common/worker/editorWorkerServer.ts | 4 --- .../editor/test/common/servicesTestUtils.ts | 5 ---- .../common/abstractPluginService.ts | 9 ++----- .../extensions/common/nativePluginService.ts | 4 --- src/vs/platform/extensions/common/plugins.ts | 22 ++++++---------- src/vs/workbench/api/node/extHost.api.impl.ts | 2 +- src/vs/workbench/node/pluginHostMain.ts | 25 +++++++++++-------- 8 files changed, 24 insertions(+), 51 deletions(-) diff --git a/src/vs/editor/browser/standalone/simpleServices.ts b/src/vs/editor/browser/standalone/simpleServices.ts index 883dda1a8bd..ecb539f1f9d 100644 --- a/src/vs/editor/browser/standalone/simpleServices.ts +++ b/src/vs/editor/browser/standalone/simpleServices.ts @@ -274,10 +274,6 @@ export class SimplePluginService extends AbstractPluginService } } - public deactivate(pluginId:string): void { - // nothing to do - } - protected _createFailedPlugin(): ActivatedPlugin { throw new Error('unexpected'); } diff --git a/src/vs/editor/common/worker/editorWorkerServer.ts b/src/vs/editor/common/worker/editorWorkerServer.ts index ec336e6af2a..6a1ddaf6b7c 100644 --- a/src/vs/editor/common/worker/editorWorkerServer.ts +++ b/src/vs/editor/common/worker/editorWorkerServer.ts @@ -67,10 +67,6 @@ class WorkerPluginService extends AbstractPluginService { } } - public deactivate(pluginId:string): void { - // nothing to do - } - protected _createFailedPlugin(): ActivatedPlugin { throw new Error('unexpected'); } diff --git a/src/vs/editor/test/common/servicesTestUtils.ts b/src/vs/editor/test/common/servicesTestUtils.ts index 0e4071fea47..c27411de854 100644 --- a/src/vs/editor/test/common/servicesTestUtils.ts +++ b/src/vs/editor/test/common/servicesTestUtils.ts @@ -120,11 +120,6 @@ class MockPluginService extends AbstractPluginService { } } - public deactivate(pluginId: string): void { - // nothing to do - } - - protected _createFailedPlugin(): any { throw new Error('not implemented'); } diff --git a/src/vs/platform/extensions/common/abstractPluginService.ts b/src/vs/platform/extensions/common/abstractPluginService.ts index 886ea29ece8..5cb2c7cd6f9 100644 --- a/src/vs/platform/extensions/common/abstractPluginService.ts +++ b/src/vs/platform/extensions/common/abstractPluginService.ts @@ -8,7 +8,7 @@ import * as nls from 'vs/nls'; import {IDisposable} from 'vs/base/common/lifecycle'; import Severity from 'vs/base/common/severity'; import {TPromise} from 'vs/base/common/winjs.base'; -import {IActivationEventListener, IMessage, IPluginDescription, IExtensionService, IPluginStatus} from 'vs/platform/extensions/common/plugins'; +import {IMessage, IPluginDescription, IExtensionService, IPluginStatus} from 'vs/platform/extensions/common/plugins'; import {PluginsRegistry} from 'vs/platform/extensions/common/pluginsRegistry'; const hasOwnProperty = Object.hasOwnProperty; @@ -65,7 +65,6 @@ export abstract class AbstractPluginService implement this.activatedPlugins = {}; } - public abstract deactivate(pluginId: string): void; protected abstract _showMessage(severity: Severity, message: string): void; protected showMessage(severity: Severity, source: string, message: string): void { @@ -79,10 +78,6 @@ export abstract class AbstractPluginService implement this._onReadyC(true); } - public registerOneTimeActivationEventListener(activationEvent: string, listener: IActivationEventListener): void { - PluginsRegistry.registerOneTimeActivationEventListener(activationEvent, listener); - } - public onReady(): TPromise { return this._onReady; } @@ -104,7 +99,7 @@ export abstract class AbstractPluginService implement }); } - public activateAndGet(pluginId: string): TPromise { + public activateById(pluginId: string): TPromise { return this._onReady.then(() => { let desc = PluginsRegistry.getPluginDescription(pluginId); if (!desc) { diff --git a/src/vs/platform/extensions/common/nativePluginService.ts b/src/vs/platform/extensions/common/nativePluginService.ts index 4c04bd5ff50..d1508ad3eb8 100644 --- a/src/vs/platform/extensions/common/nativePluginService.ts +++ b/src/vs/platform/extensions/common/nativePluginService.ts @@ -200,10 +200,6 @@ export class MainProcessPluginService extends AbstractPluginService { diff --git a/src/vs/platform/extensions/common/plugins.ts b/src/vs/platform/extensions/common/plugins.ts index 12f37e5168b..6908209741a 100644 --- a/src/vs/platform/extensions/common/plugins.ts +++ b/src/vs/platform/extensions/common/plugins.ts @@ -47,27 +47,19 @@ export interface IPluginStatus { export interface IExtensionService { serviceId: ServiceIdentifier; + /** + * Send an activation event and activate interested extensions. + */ activateByEvent(activationEvent: string): TPromise; - activateAndGet(pluginId: string): TPromise; - isActivated(pluginId: string): boolean; - - /** - * This method should be called only on shutdown! - * More work is needed for this to be called any time! - */ - deactivate(pluginId: string): void; - - /** - * To be used only by the platform once on startup. - */ - registrationDone(errors?: IMessage[]): void; - - registerOneTimeActivationEventListener(activationEvent: string, listener: IActivationEventListener): void; /** * Block on this signal any interactions with extensions. */ onReady(): TPromise; + + /** + * Get information about extensions status. + */ getPluginsStatus(): { [id: string]: IPluginStatus }; } diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 3f1ea9dc6b0..6449df70dc8 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -435,7 +435,7 @@ class Extension implements vscode.Extension { } activate(): Thenable { - return this._extensionService.activateAndGet(this.id).then(() => this.exports); + return this._extensionService.activateById(this.id).then(() => this.exports); } } diff --git a/src/vs/workbench/node/pluginHostMain.ts b/src/vs/workbench/node/pluginHostMain.ts index ff8011dadf4..8b4787052f1 100644 --- a/src/vs/workbench/node/pluginHostMain.ts +++ b/src/vs/workbench/node/pluginHostMain.ts @@ -93,13 +93,16 @@ interface ITestRunner { export class PluginHostMain { private _isTerminating: boolean; + private _contextService: IWorkspaceContextService; + private _extensionService: PluginHostPluginService; constructor( - @IWorkspaceContextService private contextService: IWorkspaceContextService, - @IExtensionService private extensionService: IExtensionService, - @IInstantiationService instantiationService: IInstantiationService + @IWorkspaceContextService contextService: IWorkspaceContextService, + @IExtensionService extensionService: IExtensionService ) { this._isTerminating = false; + this._contextService = contextService; + this._extensionService = extensionService; } public start(): TPromise { @@ -116,10 +119,10 @@ export class PluginHostMain { try { let allExtensions = PluginsRegistry.getAllPluginDescriptions(); let allExtensionsIds = allExtensions.map(ext => ext.id); - let activatedExtensions = allExtensionsIds.filter(id => this.extensionService.isActivated(id)); + let activatedExtensions = allExtensionsIds.filter(id => this._extensionService.isActivated(id)); activatedExtensions.forEach((extensionId) => { - this.extensionService.deactivate(extensionId); + this._extensionService.deactivate(extensionId); }); } catch (err) { // TODO: write to log once we have one @@ -133,7 +136,7 @@ export class PluginHostMain { private readPlugins(): TPromise { let collector = new PluginsMessageCollector(); - let env = this.contextService.getConfiguration().env; + let env = this._contextService.getConfiguration().env; return PluginHostMain.scanPlugins(collector, BUILTIN_PLUGINS_PATH, !env.disablePlugins ? env.userPluginsHome : void 0, !env.disablePlugins ? env.pluginDevelopmentPath : void 0, env.version) .then(null, err => { @@ -143,7 +146,7 @@ export class PluginHostMain { .then(extensions => { // Register & Signal done PluginsRegistry.registerPlugins(extensions); - this.extensionService.registrationDone(collector.getMessages()); + this._extensionService.registrationDone(collector.getMessages()); }) .then(() => this.handleEagerPlugins()) .then(() => this.handlePluginTests()); @@ -183,14 +186,14 @@ export class PluginHostMain { // Handle "eager" activation plugins private handleEagerPlugins(): TPromise { - this.extensionService.activateByEvent('*').then(null, (err) => { + this._extensionService.activateByEvent('*').then(null, (err) => { console.error(err); }); return this.handleWorkspaceContainsEagerPlugins(); } private handleWorkspaceContainsEagerPlugins(): TPromise { - let workspace = this.contextService.getWorkspace(); + let workspace = this._contextService.getWorkspace(); if (!workspace || !workspace.resource) { return TPromise.as(null); } @@ -226,7 +229,7 @@ export class PluginHostMain { } let activationEvent = 'workspaceContains:' + existingFileName; - this.extensionService.activateByEvent(activationEvent).then(null, (err) => { + this._extensionService.activateByEvent(activationEvent).then(null, (err) => { console.error(err); }); }); @@ -234,7 +237,7 @@ export class PluginHostMain { } private handlePluginTests(): TPromise { - let env = this.contextService.getConfiguration().env; + let env = this._contextService.getConfiguration().env; if (!env.pluginTestsPath || !env.pluginDevelopmentPath) { return TPromise.as(null); }