From 18aa226586954e51e8e16f178fe1a77e8f90f618 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 24 Jan 2022 23:49:27 +0100 Subject: [PATCH] Adopt `ILanguageFeatureDebounceService` for invoking `DocumentRangeSemanticTokensProviderRegistry` (#140557) --- .../browser/viewportSemanticTokens.ts | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/vs/editor/contrib/viewportSemanticTokens/browser/viewportSemanticTokens.ts b/src/vs/editor/contrib/viewportSemanticTokens/browser/viewportSemanticTokens.ts index e03bf3c8e695e..767b02561c6c7 100644 --- a/src/vs/editor/contrib/viewportSemanticTokens/browser/viewportSemanticTokens.ts +++ b/src/vs/editor/contrib/viewportSemanticTokens/browser/viewportSemanticTokens.ts @@ -17,6 +17,8 @@ import { isSemanticColoringEnabled, SEMANTIC_HIGHLIGHTING_SETTING_ID } from 'vs/ import { toMultilineTokens2 } from 'vs/editor/common/services/semanticTokensProviderStyling'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IThemeService } from 'vs/platform/theme/common/themeService'; +import { IFeatureDebounceInformation, ILanguageFeatureDebounceService } from 'vs/editor/common/services/languageFeatureDebounce'; +import { StopWatch } from 'vs/base/common/stopwatch'; class ViewportSemanticTokensContribution extends Disposable implements IEditorContribution { @@ -27,6 +29,7 @@ class ViewportSemanticTokensContribution extends Disposable implements IEditorCo } private readonly _editor: ICodeEditor; + private readonly _debounceInformation: IFeatureDebounceInformation; private readonly _tokenizeViewport: RunOnceScheduler; private _outstandingRequests: CancelablePromise[]; @@ -34,36 +37,43 @@ class ViewportSemanticTokensContribution extends Disposable implements IEditorCo editor: ICodeEditor, @IModelService private readonly _modelService: IModelService, @IThemeService private readonly _themeService: IThemeService, - @IConfigurationService private readonly _configurationService: IConfigurationService + @IConfigurationService private readonly _configurationService: IConfigurationService, + @ILanguageFeatureDebounceService languageFeatureDebounceService: ILanguageFeatureDebounceService ) { super(); this._editor = editor; + this._debounceInformation = languageFeatureDebounceService.for(DocumentRangeSemanticTokensProviderRegistry, 'DocumentRangeSemanticTokens', { min: 100, max: 500 }); this._tokenizeViewport = new RunOnceScheduler(() => this._tokenizeViewportNow(), 100); this._outstandingRequests = []; + const scheduleTokenizeViewport = () => { + if (this._editor.hasModel()) { + this._tokenizeViewport.schedule(this._debounceInformation.get(this._editor.getModel())); + } + }; this._register(this._editor.onDidScrollChange(() => { - this._tokenizeViewport.schedule(); + scheduleTokenizeViewport(); })); this._register(this._editor.onDidChangeModel(() => { this._cancelAll(); - this._tokenizeViewport.schedule(); + scheduleTokenizeViewport(); })); this._register(this._editor.onDidChangeModelContent((e) => { this._cancelAll(); - this._tokenizeViewport.schedule(); + scheduleTokenizeViewport(); })); this._register(DocumentRangeSemanticTokensProviderRegistry.onDidChange(() => { this._cancelAll(); - this._tokenizeViewport.schedule(); + scheduleTokenizeViewport(); })); this._register(this._configurationService.onDidChangeConfiguration(e => { if (e.affectsConfiguration(SEMANTIC_HIGHLIGHTING_SETTING_ID)) { this._cancelAll(); - this._tokenizeViewport.schedule(); + scheduleTokenizeViewport(); } })); this._register(this._themeService.onDidColorThemeChange(() => { this._cancelAll(); - this._tokenizeViewport.schedule(); + scheduleTokenizeViewport(); })); } @@ -111,7 +121,9 @@ class ViewportSemanticTokensContribution extends Disposable implements IEditorCo private _requestRange(model: ITextModel, range: Range): CancelablePromise { const requestVersionId = model.getVersionId(); const request = createCancelablePromise(token => Promise.resolve(getDocumentRangeSemanticTokens(model, range, token))); + const sw = new StopWatch(false); request.then((r) => { + this._debounceInformation.update(model, sw.elapsed()); if (!r || !r.tokens || model.isDisposed() || model.getVersionId() !== requestVersionId) { return; }