Skip to content

Commit

Permalink
[textmate] don't warn when same grammar is registered multiple times
Browse files Browse the repository at this point in the history
Fixes #6124

Signed-off-by: Sven Efftinge <sven.efftinge@typefox.io>
  • Loading branch information
svenefftinge committed Sep 6, 2019
1 parent e93b1d4 commit e2d6355
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/monaco/src/browser/textmate/textmate-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface GrammarDefinitionProvider {
export interface GrammarDefinition {
format: 'json' | 'plist';
content: object | string;
location?: string;
}

@injectable()
Expand All @@ -45,8 +46,13 @@ export class TextmateRegistry {
readonly languageIdToScope = new Map<string, string>();

registerTextmateGrammarScope(scope: string, description: GrammarDefinitionProvider): void {
if (this.scopeToProvider.has(scope)) {
console.warn(new Error(`a registered grammar provider for '${scope}' scope is overridden`));
const existingProvider = this.scopeToProvider.get(scope);
if (existingProvider) {
Promise.all([existingProvider.getGrammarDefinition(), description.getGrammarDefinition()]).then(([a, b]) => {
if (a.location !== b.location || !a.location && !b.location) {
console.warn(new Error(`a registered grammar provider for '${scope}' scope is overridden`));
}
});
}
this.scopeToProvider.set(scope, description);
}
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/plugin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ export interface GrammarsContribution {
language?: string;
scope: string;
grammar?: string | object;
grammarLocation?: string;
embeddedLanguages?: ScopeMap;
tokenTypes?: ScopeMap;
injectTo?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class GrammarsReader {
scope: rawGrammar.scopeName,
format: rawGrammar.path.endsWith('json') ? 'json' : 'plist',
grammar: grammar,
grammarLocation: rawGrammar.path,
injectTo: rawGrammar.injectTo,
embeddedLanguages: rawGrammar.embeddedLanguages,
tokenTypes: rawGrammar.tokenTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class PluginContributionHandler {
return {
format: grammar.format,
content: grammar.grammar || '',
location: grammar.grammarLocation
};
},
getInjections: (scopeName: string) =>
Expand Down

0 comments on commit e2d6355

Please sign in to comment.