Skip to content

Commit 83eb3af

Browse files
authored
Debounce chatWidget view model changes (microsoft#208120)
Currently we can end up updating the chat list multiple times per frame With this change, we try to batch some of these updates to avoid this
1 parent 57b0c14 commit 83eb3af

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/vs/workbench/contrib/chat/browser/chatWidget.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as dom from 'vs/base/browser/dom';
77
import { ITreeContextMenuEvent, ITreeElement } from 'vs/base/browser/ui/tree/tree';
88
import { disposableTimeout, timeout } from 'vs/base/common/async';
99
import { toErrorMessage } from 'vs/base/common/errorMessage';
10-
import { Emitter } from 'vs/base/common/event';
10+
import { Emitter, Event } from 'vs/base/common/event';
1111
import { Disposable, DisposableStore, IDisposable, MutableDisposable, combinedDisposable, toDisposable } from 'vs/base/common/lifecycle';
1212
import { Schemas } from 'vs/base/common/network';
1313
import { isEqual } from 'vs/base/common/resources';
@@ -589,10 +589,15 @@ export class ChatWidget extends Disposable implements IChatWidget {
589589

590590
this.container.setAttribute('data-session-id', model.sessionId);
591591
this.viewModel = this.instantiationService.createInstance(ChatViewModel, model, this._codeBlockModelCollection);
592-
this.viewModelDisposables.add(this.viewModel.onDidChange(e => {
593-
this.requestInProgress.set(this.viewModel!.requestInProgress);
592+
this.viewModelDisposables.add(Event.accumulate(this.viewModel.onDidChange, 0)(events => {
593+
if (!this.viewModel) {
594+
return;
595+
}
596+
597+
this.requestInProgress.set(this.viewModel.requestInProgress);
598+
594599
this.onDidChangeItems();
595-
if (e?.kind === 'addRequest') {
600+
if (events.some(e => e?.kind === 'addRequest')) {
596601
revealLastElement(this.tree);
597602
this.focusInput();
598603
}

0 commit comments

Comments
 (0)