diff --git a/packages/monaco/src/browser/textmate/textmate-registry.ts b/packages/monaco/src/browser/textmate/textmate-registry.ts index a487b26f3275f..7c79ec8e6c00e 100644 --- a/packages/monaco/src/browser/textmate/textmate-registry.ts +++ b/packages/monaco/src/browser/textmate/textmate-registry.ts @@ -35,6 +35,7 @@ export interface GrammarDefinitionProvider { export interface GrammarDefinition { format: 'json' | 'plist'; content: object | string; + location?: string; } @injectable() @@ -45,8 +46,13 @@ export class TextmateRegistry { readonly languageIdToScope = new Map(); 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); } diff --git a/packages/plugin-ext/src/common/plugin-protocol.ts b/packages/plugin-ext/src/common/plugin-protocol.ts index d3c64d58900c0..4c71a8ef1acc8 100644 --- a/packages/plugin-ext/src/common/plugin-protocol.ts +++ b/packages/plugin-ext/src/common/plugin-protocol.ts @@ -416,6 +416,7 @@ export interface GrammarsContribution { language?: string; scope: string; grammar?: string | object; + grammarLocation?: string; embeddedLanguages?: ScopeMap; tokenTypes?: ScopeMap; injectTo?: string[]; diff --git a/packages/plugin-ext/src/hosted/node/scanners/grammars-reader.ts b/packages/plugin-ext/src/hosted/node/scanners/grammars-reader.ts index 7aaf0c0dcb63c..2d9fcdd204e30 100644 --- a/packages/plugin-ext/src/hosted/node/scanners/grammars-reader.ts +++ b/packages/plugin-ext/src/hosted/node/scanners/grammars-reader.ts @@ -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 diff --git a/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts b/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts index d2cb71a269122..2f3d4c044db67 100644 --- a/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts +++ b/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts @@ -138,6 +138,7 @@ export class PluginContributionHandler { return { format: grammar.format, content: grammar.grammar || '', + location: grammar.grammarLocation }; }, getInjections: (scopeName: string) =>