Skip to content

Commit ea69314

Browse files
authored
1 parent 968d631 commit ea69314

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/vs/workbench/services/textMate/browser/backgroundTokenization/threadedBackgroundTokenizerFactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class ThreadedBackgroundTokenizerFactory implements IDisposable {
3838

3939
constructor(
4040
private readonly _reportTokenizationTime: (timeMs: number, languageId: string, sourceExtensionId: string | undefined, lineLength: number, isRandomSample: boolean) => void,
41+
private readonly _shouldTokenizeAsync: () => boolean,
4142
@IExtensionResourceLoaderService private readonly _extensionResourceLoaderService: IExtensionResourceLoaderService,
4243
@IModelService private readonly _modelService: IModelService,
4344
@ILanguageConfigurationService private readonly _languageConfigurationService: ILanguageConfigurationService,
@@ -55,9 +56,8 @@ export class ThreadedBackgroundTokenizerFactory implements IDisposable {
5556

5657
// Will be recreated after worker is disposed (because tokenizer is re-registered when languages change)
5758
public createBackgroundTokenizer(textModel: ITextModel, tokenStore: IBackgroundTokenizationStore, maxTokenizationLineLength: IObservable<number>): IBackgroundTokenizer | undefined {
58-
const shouldTokenizeAsync = this._configurationService.getValue<boolean>('editor.experimental.asyncTokenization');
5959
// fallback to default sync background tokenizer
60-
if (shouldTokenizeAsync !== true || textModel.isTooLargeForSyncing()) { return undefined; }
60+
if (!this._shouldTokenizeAsync() || textModel.isTooLargeForSyncing()) { return undefined; }
6161

6262
const store = new DisposableStore();
6363
const controllerContainer = this._getWorkerProxy().then((workerProxy) => {

src/vs/workbench/services/textMate/browser/textMateTokenizationFeatureImpl.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
5757
private _currentTokenColorMap: string[] | null = null;
5858
private readonly _threadedBackgroundTokenizerFactory = this._instantiationService.createInstance(
5959
ThreadedBackgroundTokenizerFactory,
60-
(timeMs, languageId, sourceExtensionId, lineLength, isRandomSample) => this._reportTokenizationTime(timeMs, languageId, sourceExtensionId, lineLength, true, isRandomSample)
60+
(timeMs, languageId, sourceExtensionId, lineLength, isRandomSample) => this._reportTokenizationTime(timeMs, languageId, sourceExtensionId, lineLength, true, isRandomSample),
61+
() => this.getAsyncTokenizationEnabled(),
6162
);
6263

6364
constructor(
@@ -89,6 +90,14 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
8990
});
9091
}
9192

93+
private getAsyncTokenizationEnabled(): boolean {
94+
return !!this._configurationService.getValue<boolean>('editor.experimental.asyncTokenization');
95+
}
96+
97+
private getAsyncTokenizationVerification(): boolean {
98+
return !!this._configurationService.getValue<boolean>('editor.experimental.asyncTokenizationVerification');
99+
}
100+
92101
private _handleGrammarsExtPoint(extensions: readonly IExtensionPointUser<ITMSyntaxExtensionPoint[]>[]): void {
93102
this._grammarDefinitions = null;
94103
if (this._grammarFactory) {
@@ -287,7 +296,7 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
287296
r.initialState,
288297
r.containsEmbeddedLanguages,
289298
(textModel, tokenStore) => this._threadedBackgroundTokenizerFactory.createBackgroundTokenizer(textModel, tokenStore, maxTokenizationLineLength),
290-
() => this._configurationService.getValue<boolean>('editor.experimental.asyncTokenizationVerification'),
299+
() => this.getAsyncTokenizationVerification(),
291300
(timeMs, lineLength, isRandomSample) => {
292301
this._reportTokenizationTime(timeMs, languageId, r.sourceExtensionId, lineLength, false, isRandomSample);
293302
},
@@ -397,6 +406,7 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
397406
fromWorker: boolean;
398407
sourceExtensionId: string | undefined;
399408
isRandomSample: boolean;
409+
tokenizationSetting: number;
400410
}, {
401411
owner: 'hediet';
402412

@@ -406,6 +416,7 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
406416
fromWorker: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'To figure out if this line was tokenized sync or async' };
407417
sourceExtensionId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'To figure out which extension contributed the grammar' };
408418
isRandomSample: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'To figure out if this is a random sample or measured because of some other condition.' };
419+
tokenizationSetting: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'To understand if the user has async tokenization enabled. 0=sync, 1=async, 2=verification' };
409420

410421
comment: 'This event gives insight about the performance certain grammars.';
411422
}>('editor.tokenizedLine', {
@@ -415,6 +426,7 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
415426
fromWorker,
416427
sourceExtensionId,
417428
isRandomSample,
429+
tokenizationSetting: this.getAsyncTokenizationEnabled() ? (this.getAsyncTokenizationVerification() ? 2 : 1) : 0,
418430
});
419431
}
420432
}

0 commit comments

Comments
 (0)