Skip to content

Commit 43a9713

Browse files
authored
chat: fix md chat response not being fully written out (microsoft#278703)
Refs microsoft#277214
1 parent 6f1d03e commit 43a9713

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/vs/workbench/contrib/chat/browser/chatContentParts/chatMarkdownContentPart.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export interface IChatMarkdownContentPartOptions {
7777
};
7878
}
7979

80+
interface IMarkdownPartCodeBlockInfo extends IChatCodeBlockInfo {
81+
isStreamingEdit: boolean;
82+
}
83+
8084
export class ChatMarkdownContentPart extends Disposable implements IChatContentPart {
8185

8286
private static ID_POOL = 0;
@@ -89,7 +93,7 @@ export class ChatMarkdownContentPart extends Disposable implements IChatContentP
8993
private readonly _onDidChangeHeight = this._register(new Emitter<void>());
9094
readonly onDidChangeHeight = this._onDidChangeHeight.event;
9195

92-
readonly codeblocks: IChatCodeBlockInfo[] = [];
96+
readonly codeblocks: IMarkdownPartCodeBlockInfo[] = [];
9397

9498
private readonly mathLayoutParticipants = new Set<() => void>();
9599

@@ -217,12 +221,13 @@ export class ChatMarkdownContentPart extends Disposable implements IChatContentP
217221
this._register(ref.object.onDidChangeContentHeight(() => this._onDidChangeHeight.fire()));
218222

219223
const ownerMarkdownPartId = this.codeblocksPartId;
220-
const info: IChatCodeBlockInfo = new class implements IChatCodeBlockInfo {
224+
const info = new class implements IMarkdownPartCodeBlockInfo {
221225
readonly ownerMarkdownPartId = ownerMarkdownPartId;
222226
readonly codeBlockIndex = globalIndex;
223227
readonly elementId = element.id;
224228
readonly chatSessionResource = element.sessionResource;
225229
readonly languageId = languageId;
230+
readonly isStreamingEdit = false;
226231
readonly editDeltaInfo = EditDeltaInfo.fromText(text);
227232
codemapperUri = undefined; // will be set async
228233
get uri() {
@@ -251,12 +256,13 @@ export class ChatMarkdownContentPart extends Disposable implements IChatContentP
251256
}
252257
this.allRefs.push(ref);
253258
const ownerMarkdownPartId = this.codeblocksPartId;
254-
const info: IChatCodeBlockInfo = new class implements IChatCodeBlockInfo {
259+
const info = new class implements IMarkdownPartCodeBlockInfo {
255260
readonly ownerMarkdownPartId = ownerMarkdownPartId;
256261
readonly codeBlockIndex = globalIndex;
257262
readonly elementId = element.id;
258263
readonly codemapperUri = codeblockEntry?.codemapperUri;
259264
readonly chatSessionResource = element.sessionResource;
265+
readonly isStreamingEdit = !isCodeBlockComplete;
260266
get uri() {
261267
return undefined;
262268
}
@@ -372,8 +378,21 @@ export class ChatMarkdownContentPart extends Disposable implements IChatContentP
372378
}
373379

374380
hasSameContent(other: IChatProgressRenderableResponseContent): boolean {
375-
return other.kind === 'markdownContent' && !!(other.content.value === this.markdown.content.value
376-
|| this.codeblocks.at(-1)?.codemapperUri !== undefined && other.content.value.lastIndexOf('```') === this.markdown.content.value.lastIndexOf('```'));
381+
if (other.kind !== 'markdownContent') {
382+
return false;
383+
}
384+
385+
if (other.content.value === this.markdown.content.value) {
386+
return true;
387+
}
388+
389+
// If we are streaming in code shown in an edit pill, do not re-render the entire content as long as it's coming in
390+
const lastCodeblock = this.codeblocks.at(-1);
391+
if (lastCodeblock && lastCodeblock.codemapperUri !== undefined && lastCodeblock.isStreamingEdit) {
392+
return other.content.value.lastIndexOf('```') === this.markdown.content.value.lastIndexOf('```');
393+
}
394+
395+
return false;
377396
}
378397

379398
layout(width: number): void {

0 commit comments

Comments
 (0)