Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect editor.maxTokenizationLineLength preference #7618

Merged
merged 1 commit into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/monaco/src/browser/textmate/monaco-textmate-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ import { LanguageGrammarDefinitionContribution, getEncodedLanguageId } from './t
import { createTextmateTokenizer, TokenizerOption } from './textmate-tokenizer';
import { TextmateRegistry } from './textmate-registry';
import { MonacoThemeRegistry } from './monaco-theme-registry';
import { EditorPreferences } from '@theia/editor/lib/browser/editor-preferences';

export const OnigasmPromise = Symbol('OnigasmPromise');
export type OnigasmPromise = Promise<IOnigLib>;

@injectable()
export class MonacoTextmateService implements FrontendApplicationContribution {

protected readonly tokenizerOption: TokenizerOption = {
lineLimit: 400
};

protected readonly _activatedLanguages = new Set<string>();

protected grammarRegistry: Registry;
Expand All @@ -52,6 +57,9 @@ export class MonacoTextmateService implements FrontendApplicationContribution {
@inject(MonacoThemeRegistry)
protected readonly monacoThemeRegistry: MonacoThemeRegistry;

@inject(EditorPreferences)
protected readonly preferences: EditorPreferences;

initialize(): void {
if (!isBasicWasmSupported) {
console.log('Textmate support deactivated because WebAssembly is not detected.');
Expand Down Expand Up @@ -92,6 +100,13 @@ export class MonacoTextmateService implements FrontendApplicationContribution {
}
});

this.tokenizerOption.lineLimit = this.preferences['editor.maxTokenizationLineLength'];
this.preferences.onPreferenceChanged(e => {
if (e.preferenceName === 'editor.maxTokenizationLineLength') {
this.tokenizerOption.lineLimit = this.preferences['editor.maxTokenizationLineLength'];
}
});

this.updateTheme();
this.themeService.onThemeChange(() => this.updateTheme());

Expand Down Expand Up @@ -164,7 +179,7 @@ export class MonacoTextmateService implements FrontendApplicationContribution {
if (!grammar) {
throw new Error(`no grammar for ${scopeName}, ${initialLanguage}, ${JSON.stringify(configuration)}`);
}
const options = configuration.tokenizerOption ? configuration.tokenizerOption : TokenizerOption.DEFAULT;
const options = configuration.tokenizerOption ? configuration.tokenizerOption : this.tokenizerOption;
const tokenizer = createTextmateTokenizer(grammar, options);
toDispose.push(monaco.languages.setTokensProvider(languageId, tokenizer));
const support = monaco.modes.TokenizationRegistry.get(languageId);
Expand Down
4 changes: 3 additions & 1 deletion packages/monaco/src/browser/textmate/textmate-tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ export interface TokenizerOption {
* If the `lineLimit` is not defined, it means, there are no line length limits. Otherwise, it must be a positive
* integer or an error will be thrown.
*/
readonly lineLimit?: number;
lineLimit?: number;

}

export namespace TokenizerOption {
/**
* The default TextMate tokenizer option.
*
* @deprecated Use the current value of `editor.maxTokenizationLineLength` preference instead.
*/
export const DEFAULT: TokenizerOption = {
lineLimit: 400
Expand Down