Skip to content

Commit

Permalink
Improve typing performance by not updating widget when nothing changed (
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet authored Mar 23, 2023
1 parent d484f15 commit d087cf3
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { h } from 'vs/base/browser/dom';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { KeybindingLabel, unthemedKeybindingLabelOptions } from 'vs/base/browser/ui/keybindingLabel/keybindingLabel';
import { Action, IAction, Separator } from 'vs/base/common/actions';
import { equals } from 'vs/base/common/arrays';
import { RunOnceScheduler } from 'vs/base/common/async';
import { Codicon } from 'vs/base/common/codicons';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -154,6 +155,10 @@ export class InlineSuggestionHintsContentWidget extends Disposable implements IC
this.previousAction.enabled = this.nextAction.enabled = false;
}, 100));

private lastCurrentSuggestionIdx = -1;
private lastSuggestionCount = -1;
private lastCommands: Command[] = [];

constructor(
private readonly editor: ICodeEditor,
private readonly withBorder: boolean,
Expand Down Expand Up @@ -186,7 +191,18 @@ export class InlineSuggestionHintsContentWidget extends Disposable implements IC
}

public update(position: Position | null, currentSuggestionIdx: number, suggestionCount: number | undefined, extraCommands: Command[]): void {
if (this.position === position
&& this.lastCurrentSuggestionIdx === currentSuggestionIdx
&& this.lastSuggestionCount === suggestionCount
&& equals(this.lastCommands, extraCommands)) {
// nothing to update
return;
}

this.position = position;
this.lastCurrentSuggestionIdx = currentSuggestionIdx;
this.lastSuggestionCount = suggestionCount ?? -1;
this.lastCommands = extraCommands;

if (suggestionCount !== undefined && suggestionCount > 1) {
this.disableButtonsDebounced.cancel();
Expand Down Expand Up @@ -298,6 +314,11 @@ export class CustomizedMenuWorkbenchToolBar extends WorkbenchToolBar {
}

setAdditionalSecondaryActions(actions: IAction[]): void {
if (equals(this.additionalActions, actions, (a, b) => a === b)) {
// don't update if the actions are the same
return;
}

this.additionalActions = actions;
this.updateToolbar();
}
Expand Down

0 comments on commit d087cf3

Please sign in to comment.