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 a0b6799
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/monaco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"jsonc-parser": "^2.0.2",
"monaco-css": "^2.5.0",
"monaco-html": "^2.5.2",
"onigasm": "2.2.1",
"onigasm": "2.2.4",
"vscode-textmate": "^4.0.1"
},
"publishConfig": {
Expand Down
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
13 changes: 7 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9287,12 +9287,13 @@ onetime@^5.1.0:
dependencies:
mimic-fn "^2.1.0"

[email protected].1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/onigasm/-/onigasm-2.2.1.tgz#d56da809d63d3bb25510e8b8e447ffe98e56bebb"
integrity sha512-pa361CpVfsWOk0MQ1jLuJ1GvEJMHEHgZmaBpOIfBbvbp2crkDHacXB6mA4vgEfO7fL0OEMUSuZjX0Q9yTx6jTg==
[email protected].4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/onigasm/-/onigasm-2.2.4.tgz#b0ad97e3d7c3080476a1e5daae4b4579a976cbba"
integrity sha512-BJKxCTsK0mrLh+A6AuNzknxaULZRKM5uywA2goluMLLCjfMm/PTUa0M7oSH1Ltb6CT1oKXn2atHR75Y3JQ0SSg==
dependencies:
lru-cache "^4.1.1"
lru-cache "^5.1.1"
tslint "^5.20.1"

oniguruma@^7.2.0:
version "7.2.1"
Expand Down Expand Up @@ -12385,7 +12386,7 @@ tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==

tslint@^5.12.0:
tslint@^5.12.0, tslint@^5.20.1:
version "5.20.1"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.20.1.tgz#e401e8aeda0152bc44dd07e614034f3f80c67b7d"
integrity sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg==
Expand Down

0 comments on commit a0b6799

Please sign in to comment.