mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
emmet - read grammars contributions through API
This commit is contained in:
parent
c9e75f42ff
commit
746dceadca
|
@ -9,7 +9,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
|
|||
import * as paths from 'vs/base/common/paths';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IExtensionMessageCollector, ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
import { IExtensionPoint, IExtensionMessageCollector, ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
import { ILineTokens, ITokenizationSupport, TokenizationRegistry } from 'vs/editor/common/modes';
|
||||
import { TMState } from 'vs/editor/common/modes/TMState';
|
||||
import { LineTokens } from 'vs/editor/common/modes/supports';
|
||||
|
@ -26,7 +26,7 @@ export interface ITMSyntaxExtensionPoint {
|
|||
}
|
||||
|
||||
// TODO@Martin TS(2.0.2) - Type IJsonSchema has no defined property require. Keeping semantic using any cast
|
||||
let grammarsExtPoint = ExtensionsRegistry.registerExtensionPoint<ITMSyntaxExtensionPoint[]>('grammars', <any>{
|
||||
export const grammarsExtPoint: IExtensionPoint<ITMSyntaxExtensionPoint[]> = ExtensionsRegistry.registerExtensionPoint<ITMSyntaxExtensionPoint[]>('grammars', <any>{
|
||||
description: nls.localize('vscode.extension.contributes.grammars', 'Contributes textmate tokenizers.'),
|
||||
type: 'array',
|
||||
defaultSnippets: [{ body: [{ language: '{{id}}', scopeName: 'source.{{id}}', path: './syntaxes/{{id}}.tmLanguage.' }] }],
|
||||
|
|
|
@ -9,8 +9,9 @@ import { IDisposable } from 'vs/base/common/lifecycle';
|
|||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { CommandService } from 'vs/platform/commands/common/commandService';
|
||||
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
|
||||
import { IExtensionService, ExtensionPointContribution } from 'vs/platform/extensions/common/extensions';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { IExtensionPoint } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
|
||||
class SimpleExtensionService implements IExtensionService {
|
||||
_serviceBrand: any;
|
||||
|
@ -20,6 +21,9 @@ class SimpleExtensionService implements IExtensionService {
|
|||
onReady(): TPromise<boolean> {
|
||||
return TPromise.as(true);
|
||||
}
|
||||
readExtensionPointContributions<T>(extPoint:IExtensionPoint<T>): TPromise<ExtensionPointContribution<T>[]> {
|
||||
return TPromise.as([]);
|
||||
}
|
||||
getExtensionsStatus() {
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
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 } from 'vs/platform/extensions/common/extensions';
|
||||
import { ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
import { IExtensionDescription, IExtensionService, IExtensionsStatus, ExtensionPointContribution } from 'vs/platform/extensions/common/extensions';
|
||||
import { IExtensionPoint, ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
|
||||
const hasOwnProperty = Object.hasOwnProperty;
|
||||
|
||||
|
@ -59,6 +59,23 @@ export abstract class AbstractExtensionService<T extends ActivatedExtension> imp
|
|||
return this._onReady;
|
||||
}
|
||||
|
||||
public readExtensionPointContributions<T>(extPoint: IExtensionPoint<T>): TPromise<ExtensionPointContribution<T>[]> {
|
||||
return this.onReady().then(() => {
|
||||
let availableExtensions = ExtensionsRegistry.getAllExtensionDescriptions();
|
||||
|
||||
let result: ExtensionPointContribution<T>[] = [], resultLen = 0;
|
||||
for (let i = 0, len = availableExtensions.length; i < len; i++) {
|
||||
let desc = availableExtensions[i];
|
||||
|
||||
if (desc.contributes && hasOwnProperty.call(desc.contributes, extPoint.name)) {
|
||||
result[resultLen++] = new ExtensionPointContribution<T>(desc, desc.contributes[extPoint.name]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
public getExtensionsStatus(): { [id: string]: IExtensionsStatus } {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import Severity from 'vs/base/common/severity';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IExtensionPoint } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
|
||||
export interface IExtensionDescription {
|
||||
readonly id: string;
|
||||
|
@ -44,6 +45,16 @@ export interface IExtensionsStatus {
|
|||
messages: IMessage[];
|
||||
}
|
||||
|
||||
export class ExtensionPointContribution<T> {
|
||||
readonly description: IExtensionDescription;
|
||||
readonly value: T;
|
||||
|
||||
constructor(description: IExtensionDescription, value: T) {
|
||||
this.description = description;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IExtensionService {
|
||||
_serviceBrand: any;
|
||||
|
||||
|
@ -57,6 +68,11 @@ export interface IExtensionService {
|
|||
*/
|
||||
onReady(): TPromise<boolean>;
|
||||
|
||||
/**
|
||||
* Read all contributions to an extension point.
|
||||
*/
|
||||
readExtensionPointContributions<T>(extPoint: IExtensionPoint<T>): TPromise<ExtensionPointContribution<T>[]>;
|
||||
|
||||
/**
|
||||
* Get information about extensions status.
|
||||
*/
|
||||
|
|
|
@ -10,11 +10,11 @@ import { ICommonCodeEditor, EditorContextKeys } from 'vs/editor/common/editorCom
|
|||
import { EditorAction, ServicesAccessor } from 'vs/editor/common/editorCommonExtensions';
|
||||
import { ICommandKeybindingsOptions } from 'vs/editor/common/config/config';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
import { grammarsExtPoint, ITMSyntaxExtensionPoint } from 'vs/editor/node/textMate/TMSyntax';
|
||||
|
||||
import { EditorAccessor, IGrammarContributions } from 'vs/workbench/parts/emmet/node/editorAccessor';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
|
||||
import { IExtensionService, ExtensionPointContribution } from 'vs/platform/extensions/common/extensions';
|
||||
import * as emmet from 'emmet';
|
||||
|
||||
interface IEmmetConfiguration {
|
||||
|
@ -34,25 +34,20 @@ class GrammarContributions implements IGrammarContributions {
|
|||
|
||||
private static _grammars: ModeScopeMap = null;
|
||||
|
||||
constructor() {
|
||||
constructor(contributions: ExtensionPointContribution<ITMSyntaxExtensionPoint[]>[]) {
|
||||
if (GrammarContributions._grammars === null) {
|
||||
this.fillModeScopeMap();
|
||||
this.fillModeScopeMap(contributions);
|
||||
}
|
||||
}
|
||||
|
||||
private fillModeScopeMap() {
|
||||
private fillModeScopeMap(contributions: ExtensionPointContribution<ITMSyntaxExtensionPoint[]>[]) {
|
||||
GrammarContributions._grammars = {};
|
||||
ExtensionsRegistry.getAllExtensionDescriptions().forEach((desc) => {
|
||||
if (desc.contributes) {
|
||||
let grammars = (<any>desc.contributes).grammars;
|
||||
if (grammars) {
|
||||
grammars.forEach((grammar) => {
|
||||
if (grammar.language && grammar.scopeName) {
|
||||
GrammarContributions._grammars[grammar.language] = grammar.scopeName;
|
||||
}
|
||||
});
|
||||
contributions.forEach((contribution) => {
|
||||
contribution.value.forEach((grammar) => {
|
||||
if (grammar.language && grammar.scopeName) {
|
||||
GrammarContributions._grammars[grammar.language] = grammar.scopeName;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -140,8 +135,8 @@ export abstract class EmmetEditorAction extends EditorAction {
|
|||
private _withGrammarContributions(extensionService: IExtensionService): TPromise<GrammarContributions> {
|
||||
if (this._lastExtensionService !== extensionService) {
|
||||
this._lastExtensionService = extensionService;
|
||||
this._lastGrammarContributions = extensionService.onReady().then(() => {
|
||||
return new GrammarContributions();
|
||||
this._lastGrammarContributions = extensionService.readExtensionPointContributions(grammarsExtPoint).then((contributions) => {
|
||||
return new GrammarContributions(contributions);
|
||||
});
|
||||
}
|
||||
return this._lastGrammarContributions;
|
||||
|
|
Loading…
Reference in a new issue