Skip to content

Commit b61725b

Browse files
authored
Merge pull request microsoft#51265 from wistcc/WC/51127
Adding warning when tokenization is skipped
2 parents 7a6092b + 6dca868 commit b61725b

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • src/vs/workbench/services/textMate/electron-browser

src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/t
2222
import { nullTokenize2 } from 'vs/editor/common/modes/nullMode';
2323
import { generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/tokenization';
2424
import { Color } from 'vs/base/common/color';
25+
import { INotificationService } from 'vs/platform/notification/common/notification';
2526
import URI from 'vs/base/common/uri';
2627

2728
export class TMScopeRegistry {
@@ -139,6 +140,7 @@ export class TextMateService implements ITextMateService {
139140
private _scopeRegistry: TMScopeRegistry;
140141
private _injections: { [scopeName: string]: string[]; };
141142
private _injectedEmbeddedLanguages: { [scopeName: string]: IEmbeddedLanguagesMap[]; };
143+
private _notificationService: INotificationService;
142144

143145
private _languageToScope: Map<string, string>;
144146
private _styleElement: HTMLStyleElement;
@@ -149,7 +151,8 @@ export class TextMateService implements ITextMateService {
149151

150152
constructor(
151153
@IModeService modeService: IModeService,
152-
@IWorkbenchThemeService themeService: IWorkbenchThemeService
154+
@IWorkbenchThemeService themeService: IWorkbenchThemeService,
155+
@INotificationService notificationService: INotificationService
153156
) {
154157
this._styleElement = dom.createStyleSheet();
155158
this._styleElement.className = 'vscode-tokens-styles';
@@ -160,6 +163,7 @@ export class TextMateService implements ITextMateService {
160163
this._injections = {};
161164
this._injectedEmbeddedLanguages = {};
162165
this._languageToScope = new Map<string, string>();
166+
this._notificationService = notificationService;
163167

164168
this._grammarRegistry = null;
165169

@@ -383,7 +387,7 @@ export class TextMateService implements ITextMateService {
383387

384388
private registerDefinition(modeId: string): void {
385389
this._createGrammar(modeId).then((r) => {
386-
TokenizationRegistry.register(modeId, new TMTokenization(this._scopeRegistry, r.languageId, r.grammar, r.initialState, r.containsEmbeddedLanguages));
390+
TokenizationRegistry.register(modeId, new TMTokenization(this._scopeRegistry, r.languageId, r.grammar, r.initialState, r.containsEmbeddedLanguages, this._notificationService));
387391
}, onUnexpectedError);
388392
}
389393
}
@@ -396,8 +400,9 @@ class TMTokenization implements ITokenizationSupport {
396400
private readonly _containsEmbeddedLanguages: boolean;
397401
private readonly _seenLanguages: boolean[];
398402
private readonly _initialState: StackElement;
403+
private _tokenizationWarningAlreadyShown: boolean;
399404

400-
constructor(scopeRegistry: TMScopeRegistry, languageId: LanguageId, grammar: IGrammar, initialState: StackElement, containsEmbeddedLanguages: boolean) {
405+
constructor(scopeRegistry: TMScopeRegistry, languageId: LanguageId, grammar: IGrammar, initialState: StackElement, containsEmbeddedLanguages: boolean, @INotificationService private notificationService: INotificationService) {
401406
this._scopeRegistry = scopeRegistry;
402407
this._languageId = languageId;
403408
this._grammar = grammar;
@@ -421,6 +426,10 @@ class TMTokenization implements ITokenizationSupport {
421426

422427
// Do not attempt to tokenize if a line has over 20k
423428
if (line.length >= 20000) {
429+
if (!this._tokenizationWarningAlreadyShown) {
430+
this._tokenizationWarningAlreadyShown = true;
431+
this.notificationService.warn(nls.localize('too many characters', "Tokenization is skipped for lines longer than 20k characters for performance reasons."));
432+
}
424433
console.log(`Line (${line.substr(0, 15)}...): longer than 20k characters, tokenization skipped.`);
425434
return nullTokenize2(this._languageId, line, state, offsetDelta);
426435
}

0 commit comments

Comments
 (0)