mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Further simplifications to ExtensionsRegistry
This commit is contained in:
parent
17243e765a
commit
ccfaf9796a
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
import { onWillActivate } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
import { ModesRegistry } from 'vs/editor/common/modes/modesRegistry';
|
||||
import { IMonarchLanguage } from 'vs/editor/common/modes/monarch/monarchTypes';
|
||||
import { ILanguageExtensionPoint } from 'vs/editor/common/services/modeService';
|
||||
|
@ -45,15 +45,16 @@ export function getLanguages(): ILanguageExtensionPoint[] {
|
|||
* @event
|
||||
*/
|
||||
export function onLanguage(languageId: string, callback: () => void): IDisposable {
|
||||
let isDisposed = false;
|
||||
ExtensionsRegistry.registerOneTimeActivationEventListener('onLanguage:' + languageId, () => {
|
||||
if (!isDisposed) {
|
||||
const desired = 'onLanguage:' + languageId;
|
||||
let disposable = onWillActivate.event((activationEvent) => {
|
||||
if (activationEvent === desired) {
|
||||
// stop listening
|
||||
disposable.dispose();
|
||||
// invoke actual listener
|
||||
callback();
|
||||
}
|
||||
});
|
||||
return {
|
||||
dispose: () => { isDisposed = true; }
|
||||
};
|
||||
return disposable;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,7 +8,7 @@ import * as nls from 'vs/nls';
|
|||
import Severity from 'vs/base/common/severity';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IExtensionDescription, IExtensionService, IExtensionsStatus, ExtensionPointContribution } from 'vs/platform/extensions/common/extensions';
|
||||
import { IExtensionPoint, ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
import { IExtensionPoint, ExtensionsRegistry, onWillActivate } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
|
||||
const hasOwnProperty = Object.hasOwnProperty;
|
||||
|
||||
|
@ -86,7 +86,7 @@ export abstract class AbstractExtensionService<T extends ActivatedExtension> imp
|
|||
|
||||
public activateByEvent(activationEvent: string): TPromise<void> {
|
||||
return this._onReady.then(() => {
|
||||
ExtensionsRegistry.triggerActivationEventListeners(activationEvent);
|
||||
onWillActivate.fire(activationEvent);
|
||||
let activateExtensions = ExtensionsRegistry.getExtensionDescriptionsForActivationEvent(activationEvent);
|
||||
return this._activateExtensions(activateExtensions, 0);
|
||||
});
|
||||
|
|
|
@ -25,10 +25,6 @@ export interface IExtensionDescription {
|
|||
readonly contributes?: { [point: string]: any; };
|
||||
}
|
||||
|
||||
export interface IActivationEventListener {
|
||||
(): void;
|
||||
}
|
||||
|
||||
export const IExtensionService = createDecorator<IExtensionService>('extensionService');
|
||||
|
||||
export interface IMessage {
|
||||
|
|
|
@ -8,9 +8,12 @@ import * as nls from 'vs/nls';
|
|||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { IJSONSchema } from 'vs/base/common/jsonSchema';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { IActivationEventListener, IMessage, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import { IMessage, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import { Extensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
|
||||
import { Registry } from 'vs/platform/platform';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
|
||||
export const onWillActivate: Emitter<string> = new Emitter<string>();
|
||||
|
||||
export interface IExtensionMessageCollector {
|
||||
error(message: string): void;
|
||||
|
@ -80,9 +83,6 @@ export interface IExtensionsRegistry {
|
|||
getAllExtensionDescriptions(): IExtensionDescription[];
|
||||
getExtensionDescription(extensionId: string): IExtensionDescription;
|
||||
|
||||
registerOneTimeActivationEventListener(activationEvent: string, listener: IActivationEventListener): void;
|
||||
triggerActivationEventListeners(activationEvent: string): void;
|
||||
|
||||
registerExtensionPoint<T>(extensionPoint: string, deps: IExtensionPoint<any>[], jsonSchema: IJSONSchema): IExtensionPoint<T>;
|
||||
getExtensionPoints(): ExtensionPoint<any>[];
|
||||
}
|
||||
|
@ -262,7 +262,6 @@ class ExtensionsRegistryImpl implements IExtensionsRegistry {
|
|||
private _extensionsMap: IExtensionDescriptionMap;
|
||||
private _extensionsArr: IExtensionDescription[];
|
||||
private _activationMap: { [activationEvent: string]: IExtensionDescription[]; };
|
||||
private _oneTimeActivationEventListeners: { [activationEvent: string]: IActivationEventListener[]; };
|
||||
private _extensionPoints: { [extPoint: string]: ExtensionPoint<any>; };
|
||||
|
||||
constructor() {
|
||||
|
@ -270,7 +269,6 @@ class ExtensionsRegistryImpl implements IExtensionsRegistry {
|
|||
this._extensionsArr = [];
|
||||
this._activationMap = {};
|
||||
this._extensionPoints = {};
|
||||
this._oneTimeActivationEventListeners = {};
|
||||
}
|
||||
|
||||
public registerExtensionPoint<T>(extensionPoint: string, deps: IExtensionPoint<any>[], jsonSchema: IJSONSchema): IExtensionPoint<T> {
|
||||
|
@ -330,30 +328,6 @@ class ExtensionsRegistryImpl implements IExtensionsRegistry {
|
|||
}
|
||||
return this._extensionsMap[extensionId];
|
||||
}
|
||||
|
||||
public registerOneTimeActivationEventListener(activationEvent: string, listener: IActivationEventListener): void {
|
||||
if (!hasOwnProperty.call(this._oneTimeActivationEventListeners, activationEvent)) {
|
||||
this._oneTimeActivationEventListeners[activationEvent] = [];
|
||||
}
|
||||
this._oneTimeActivationEventListeners[activationEvent].push(listener);
|
||||
}
|
||||
|
||||
public triggerActivationEventListeners(activationEvent: string): void {
|
||||
if (hasOwnProperty.call(this._oneTimeActivationEventListeners, activationEvent)) {
|
||||
let listeners = this._oneTimeActivationEventListeners[activationEvent];
|
||||
delete this._oneTimeActivationEventListeners[activationEvent];
|
||||
|
||||
for (let i = 0, len = listeners.length; i < len; i++) {
|
||||
let listener = listeners[i];
|
||||
try {
|
||||
listener();
|
||||
} catch (e) {
|
||||
onUnexpectedError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue