Skip to content

Commit 95f2ccd

Browse files
authored
Don't count codeblocks as words in chat rendering calculation (microsoft#251963)
* Don't count codeblocks as words in chat rendering calculation * Shorter max wait time
1 parent 144e9c6 commit 95f2ccd

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/vs/workbench/contrib/chat/common/chatViewModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ export class ChatResponseViewModel extends Disposable implements IChatResponseVi
606606
this._contentUpdateTimings.lastUpdateTime = now;
607607
}
608608

609-
const timeDiff = Math.min(now - this._contentUpdateTimings.lastUpdateTime, 1000);
609+
const timeDiff = Math.min(now - this._contentUpdateTimings.lastUpdateTime, 500);
610610
const newTotalTime = Math.max(this._contentUpdateTimings.totalTime + timeDiff, 250);
611611
const impliedWordLoadRate = wordCount / (newTotalTime / 1000);
612612
this.trace('onDidChange', `Update- got ${wordCount} words over last ${newTotalTime}ms = ${impliedWordLoadRate} words/s`);

src/vs/workbench/contrib/chat/common/chatWordCounter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export function getNWords(str: string, numWordsToCount: number): IWordCountResul
4646
// One chinese character
4747
// One or more + - =, handled so that code like "a=1+2-3" is broken up better
4848
// One or more characters that aren't whitepace or any of the above
49-
const allWordMatches = Array.from(str.matchAll(new RegExp(linkPattern + r`|\p{sc=Han}|=+|\++|-+|[^\s\|\p{sc=Han}|=|\+|\-]+`, 'gu')));
49+
const backtick = '`';
50+
const allWordMatches = Array.from(str.matchAll(new RegExp(linkPattern + r`|\p{sc=Han}|=+|\++|-+|[^\s\|\p{sc=Han}|=|\+|\-|${backtick}]+`, 'gu')));
5051

5152
const targetWords = allWordMatches.slice(0, numWordsToCount);
5253

src/vs/workbench/contrib/chat/test/common/chatWordCounter.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ suite('ChatWordCounter', () => {
8787
cases.forEach(([str, nWords, result]) => doTest(str, nWords, result));
8888
});
8989

90+
test('codeblocks', () => {
91+
const cases: [string, number, string][] = [
92+
['hello\n\n```\n```\n\nworld foo', 2, 'hello\n\n```\n```\n\nworld'],
93+
];
94+
95+
cases.forEach(([str, nWords, result]) => doTest(str, nWords, result));
96+
});
97+
9098
test('chinese characters', () => {
9199
const cases: [string, number, string][] = [
92100
['我喜欢中国菜', 3, '我喜欢'],

0 commit comments

Comments
 (0)