Skip to content

Commit 73f8b07

Browse files
authored
Add setting to skip word counting/render smoothing (microsoft#250912)
1 parent 0bbc5c8 commit 73f8b07

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/vs/base/common/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export namespace Event {
325325
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
326326
* returned event causes this utility to leak a listener on the original event.
327327
*/
328-
export function accumulate<T>(event: Event<T>, delay: number = 0, disposable?: DisposableStore): Event<T[]> {
328+
export function accumulate<T>(event: Event<T>, delay: number | typeof MicrotaskDelay = 0, disposable?: DisposableStore): Event<T[]> {
329329
return Event.debounce<T, T[]>(event, (last, e) => {
330330
if (!last) {
331331
return [e];

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
168168
private readonly codeBlockModelCollection: CodeBlockModelCollection,
169169
overflowWidgetsDomNode: HTMLElement | undefined,
170170
@IInstantiationService private readonly instantiationService: IInstantiationService,
171-
@IConfigurationService configService: IConfigurationService,
171+
@IConfigurationService private readonly configService: IConfigurationService,
172172
@ILogService private readonly logService: ILogService,
173173
@IContextKeyService private readonly contextKeyService: IContextKeyService,
174174
@IThemeService private readonly themeService: IThemeService,
@@ -798,6 +798,9 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
798798
private getNextProgressiveRenderContent(element: IChatResponseViewModel): { content: IChatRendererContent[]; moreContentAvailable: boolean } {
799799
const data = this.getDataForProgressiveRender(element);
800800

801+
// An unregistered setting for development- skip the word counting and smoothing, just render content as it comes in
802+
const renderImmediately = this.configService.getValue<boolean>('chat.experimental.renderMarkdownImmediately') === true;
803+
801804
const renderableResponse = annotateSpecialMarkdownContent(element.response.value);
802805

803806
this.traceLayout('getNextProgressiveRenderContent', `Want to render ${data.numWordsToRender} at ${data.rate} words/s, counting...`);
@@ -811,7 +814,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
811814
let moreContentAvailable = false;
812815
for (let i = 0; i < renderableResponse.length; i++) {
813816
const part = renderableResponse[i];
814-
if (part.kind === 'markdownContent') {
817+
if (part.kind === 'markdownContent' && !renderImmediately) {
815818
const wordCountResult = getNWords(part.content.value, numNeededWords);
816819
this.traceLayout('getNextProgressiveRenderContent', ` Chunk ${i}: Want to render ${numNeededWords} words and found ${wordCountResult.returnedWordCount} words. Total words in chunk: ${wordCountResult.totalWordCount}`);
817820
numNeededWords -= wordCountResult.returnedWordCount;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import './media/chat.css';
6767
import './media/chatAgentHover.css';
6868
import './media/chatViewWelcome.css';
6969
import { ChatViewWelcomePart } from './viewsWelcome/chatViewWelcomeController.js';
70+
import { MicrotaskDelay } from '../../../../base/common/symbols.js';
7071

7172
const $ = dom.$;
7273

@@ -1077,7 +1078,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
10771078

10781079
this.container.setAttribute('data-session-id', model.sessionId);
10791080
this.viewModel = this.instantiationService.createInstance(ChatViewModel, model, this._codeBlockModelCollection);
1080-
this.viewModelDisposables.add(Event.runAndSubscribe(Event.accumulate(this.viewModel.onDidChange, 0), (events => {
1081+
const renderImmediately = this.configurationService.getValue<boolean>('chat.experimental.renderMarkdownImmediately') === true;
1082+
const delay = renderImmediately ? MicrotaskDelay : 0;
1083+
this.viewModelDisposables.add(Event.runAndSubscribe(Event.accumulate(this.viewModel.onDidChange, delay), (events => {
10811084
if (!this.viewModel) {
10821085
return;
10831086
}

0 commit comments

Comments
 (0)