Skip to content

Commit

Permalink
plugin-ext: late textmate grammar activation
Browse files Browse the repository at this point in the history
There is a race condition when the layout is restored: if an editor was
opened, it will be restored and wait for some language activation event.
The issue with this was first seen with the builtin cpp extension: two
cpp grammars are contributed, but the first one is not the right one to
use on a cpp file. When an editor opened, the first bogus grammar is
loaded and activated, triggering bogus coloration.

This commit ensures that all grammars are more correctly contributed
before activating anything in the next event-loop tick.

Signed-off-by: Paul Maréchal <[email protected]>
  • Loading branch information
paul-marechal committed Apr 9, 2020
1 parent cb3db2a commit 78f839a
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,33 @@ export class PluginContributionHandler {
getInjections: (scopeName: string) =>
this.injections.get(scopeName)!
}));

// load grammars on next tick to await registration of languages from all plugins in current tick
// see https://github.com/eclipse-theia/theia/issues/6907#issuecomment-578600243
setTimeout(() => {
}
// load grammars on next tick to await registration of languages from all plugins in current tick
// see https://github.com/eclipse-theia/theia/issues/6907#issuecomment-578600243
setTimeout(() => {
for (const grammar of grammars) {
const language = grammar.language;
if (language) {
pushContribution(`grammar.language.${language}.scope`, () => this.grammarsRegistry.mapLanguageIdToTextmateGrammar(language, grammar.scope));
pushContribution(`grammar.language.${language}.configuration`, () => this.grammarsRegistry.registerGrammarConfiguration(language, {
embeddedLanguages: this.convertEmbeddedLanguages(grammar.embeddedLanguages, logError),
tokenTypes: this.convertTokenTypes(grammar.tokenTypes)
}));
pushContribution(`grammar.language.${language}.activation`,
() => this.monacoTextmateService.activateLanguage(language)
);
}
}
// activate grammars only once everything else is loaded.
// see https://github.com/eclipse-theia/theia-cpp-extensions/issues/100#issuecomment-610643866
setTimeout(() => {
for (const grammar of grammars) {
const language = grammar.language;
if (language) {
pushContribution(`grammar.language.${language}.activation`,
() => this.monacoTextmateService.activateLanguage(language)
);
}
}
});
}
});
}

pushContribution('commands', () => this.registerCommands(contributions));
Expand Down

0 comments on commit 78f839a

Please sign in to comment.