Skip to content

Commit

Permalink
linked editing: adopt ILanguageFeatureDebounceService. For #140557
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Feb 8, 2022
1 parent 1d79533 commit 0119d8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/vs/editor/contrib/linkedEditing/browser/linkedEditing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { registerThemingParticipant } from 'vs/platform/theme/common/themeServic
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry';
import { ISingleEditOperation } from 'vs/editor/common/core/editOperation';
import { IFeatureDebounceInformation, ILanguageFeatureDebounceService } from 'vs/editor/common/services/languageFeatureDebounce';
import { StopWatch } from 'vs/base/common/stopwatch';

export const CONTEXT_ONTYPE_RENAME_INPUT_VISIBLE = new RawContextKey<boolean>('LinkedEditingInputVisible', false);

Expand All @@ -52,13 +54,14 @@ export class LinkedEditingContribution extends Disposable implements IEditorCont
return editor.getContribution<LinkedEditingContribution>(LinkedEditingContribution.ID);
}

private _debounceDuration = 200;
private _debounceDuration: number | undefined;

private readonly _editor: ICodeEditor;
private readonly _providers: LanguageFeatureRegistry<LinkedEditingRangeProvider>;
private _enabled: boolean;

private readonly _visibleContextKey: IContextKey<boolean>;
private readonly _debounceInformation: IFeatureDebounceInformation;

private _rangeUpdateTriggerPromise: Promise<any> | null;
private _rangeSyncTriggerPromise: Promise<any> | null;
Expand All @@ -79,12 +82,14 @@ export class LinkedEditingContribution extends Disposable implements IEditorCont
@IContextKeyService contextKeyService: IContextKeyService,
@ILanguageFeaturesService languageFeaturesService: ILanguageFeaturesService,
@ILanguageConfigurationService private readonly languageConfigurationService: ILanguageConfigurationService,
@ILanguageFeatureDebounceService languageFeatureDebounceService: ILanguageFeatureDebounceService
) {
super();
this._editor = editor;
this._providers = languageFeaturesService.linkedEditingRangeProvider;
this._enabled = false;
this._visibleContextKey = CONTEXT_ONTYPE_RENAME_INPUT_VISIBLE.bindTo(contextKeyService);
this._debounceInformation = languageFeatureDebounceService.for(this._providers, 'Linked Editing', { min: 200 });

this._currentDecorations = [];
this._languageWordPattern = null;
Expand Down Expand Up @@ -137,9 +142,9 @@ export class LinkedEditingContribution extends Disposable implements IEditorCont
)
);

const rangeUpdateScheduler = new Delayer(this._debounceDuration);
const rangeUpdateScheduler = new Delayer(this._debounceInformation.get(model));
const triggerRangeUpdate = () => {
this._rangeUpdateTriggerPromise = rangeUpdateScheduler.trigger(() => this.updateRanges(), this._debounceDuration);
this._rangeUpdateTriggerPromise = rangeUpdateScheduler.trigger(() => this.updateRanges(), this._debounceDuration ?? this._debounceInformation.get(model));
};
const rangeSyncScheduler = new Delayer(0);
const triggerRangeSync = (decorations: string[]) => {
Expand All @@ -162,8 +167,8 @@ export class LinkedEditingContribution extends Disposable implements IEditorCont
}));
this._localToDispose.add({
dispose: () => {
rangeUpdateScheduler.cancel();
rangeSyncScheduler.cancel();
rangeUpdateScheduler.dispose();
rangeSyncScheduler.dispose();
}
});
this.updateRanges();
Expand Down Expand Up @@ -297,7 +302,9 @@ export class LinkedEditingContribution extends Disposable implements IEditorCont
this._currentRequestModelVersion = modelVersionId;
const request = createCancelablePromise(async token => {
try {
const sw = new StopWatch(false);
const response = await getLinkedEditingRanges(this._providers, model, position, token);
this._debounceInformation.update(model, sw.elapsed());
if (request !== this._currentRequest) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ suite('linked editing', () => {
editor.updateOptions({ linkedEditing: true });
const linkedEditingContribution = editor.registerAndInstantiateContribution(
LinkedEditingContribution.ID,
LinkedEditingContribution
LinkedEditingContribution,
);
linkedEditingContribution.setDebounceDuration(0);

Expand Down

0 comments on commit 0119d8c

Please sign in to comment.