From cf43084d6d08f7e78ff3f359d6c2fc3630dfa05b Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Tue, 15 Oct 2024 00:17:48 -0700 Subject: [PATCH] fix: filter `textEditGroup` when annotating markdown content (#231375) --- src/vs/workbench/contrib/chat/common/annotations.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/chat/common/annotations.ts b/src/vs/workbench/contrib/chat/common/annotations.ts index bd95ecb599eda..fb2e11f5a91a4 100644 --- a/src/vs/workbench/contrib/chat/common/annotations.ts +++ b/src/vs/workbench/contrib/chat/common/annotations.ts @@ -23,7 +23,8 @@ export type ContentRefData = export function annotateSpecialMarkdownContent(response: ReadonlyArray): IChatProgressRenderableResponseContent[] { const result: IChatProgressRenderableResponseContent[] = []; for (const item of response) { - const previousItem = result[result.length - 1]; + const previousItem = result.filter(p => p.kind !== 'textEditGroup').at(-1); + const previousItemIndex = result.findIndex(p => p === previousItem); if (item.kind === 'inlineReference') { const location: ContentRefData = 'uri' in item.inlineReference ? item.inlineReference @@ -44,20 +45,20 @@ export function annotateSpecialMarkdownContent(response: ReadonlyArray${item.content.value}`; if (previousItem?.kind === 'markdownContent') { // Since this is inside a codeblock, it needs to be merged into the previous markdown content. const merged = appendMarkdownString(previousItem.content, new MarkdownString(markdownText)); - result[result.length - 1] = { content: merged, kind: 'markdownContent' }; + result[previousItemIndex] = { content: merged, kind: 'markdownContent' }; } else { result.push({ content: new MarkdownString(markdownText), kind: 'markdownContent' }); } @@ -65,7 +66,7 @@ export function annotateSpecialMarkdownContent(response: ReadonlyArray${item.uri.toString()}`; const merged = appendMarkdownString(previousItem.content, new MarkdownString(markdownText)); - result[result.length - 1] = { content: merged, kind: 'markdownContent' }; + result[previousItemIndex] = { content: merged, kind: 'markdownContent' }; } } else { result.push(item);