Skip to content

Commit

Permalink
refactor: reuse IChatResponseViewModel#isComplete (microsoft#230656)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl authored Oct 6, 2024
1 parent dc265ad commit 9944c35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import { IChatRendererDelegate } from '../chatListRenderer.js';
import { ChatMarkdownDecorationsRenderer } from '../chatMarkdownDecorationsRenderer.js';
import { ChatEditorOptions } from '../chatOptions.js';
import { CodeBlockPart, ICodeBlockData, localFileLanguageId, parseLocalFileData } from '../codeBlockPart.js';
import '../media/chatCodeBlockPill.css';
import { IDisposableReference, ResourcePool } from './chatCollections.js';
import { IChatContentPart, IChatContentPartRenderContext } from './chatContentParts.js';
import '../media/chatCodeBlockPill.css';

const $ = dom.$;

Expand All @@ -59,7 +59,6 @@ export class ChatMarkdownContentPart extends Disposable implements IChatContentP
currentWidth: number,
private readonly codeBlockModelCollection: CodeBlockModelCollection,
private readonly rendererOptions: IChatListItemRendererOptions,
isResponseComplete: boolean,
@IContextKeyService contextKeyService: IContextKeyService,
@ITextModelService private readonly textModelService: ITextModelService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
Expand All @@ -75,7 +74,7 @@ export class ChatMarkdownContentPart extends Disposable implements IChatContentP
const result = this._register(renderer.render(markdown, {
fillInIncompleteTokens,
codeBlockRendererSync: (languageId, text, raw) => {
const isCodeBlockComplete = isResponseComplete || !raw || raw?.endsWith('```');
const isCodeBlockComplete = !isResponseVM(context.element) || context.element.isComplete || !raw || raw?.endsWith('```');
const index = codeBlockIndex++;
let textModel: Promise<IResolvedTextEditorModel>;
let range: Range | undefined;
Expand Down
12 changes: 6 additions & 6 deletions src/vs/workbench/contrib/chat/browser/chatListRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
content: value,
preceedingContentParts: parts,
};
const newPart = this.renderChatContentPart(data, templateData, context, false);
const newPart = this.renderChatContentPart(data, templateData, context);
if (newPart) {
templateData.value.appendChild(newPart.domNode);
parts.push(newPart);
Expand Down Expand Up @@ -650,7 +650,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
preceedingContentParts,
contentIndex: index,
};
const newPart = this.renderChatContentPart(partToRender, templateData, context, true);
const newPart = this.renderChatContentPart(partToRender, templateData, context);
if (newPart) {
// Maybe the part can't be rendered in this context, but this shouldn't really happen
if (alreadyRenderedPart) {
Expand Down Expand Up @@ -766,7 +766,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
return diff;
}

private renderChatContentPart(content: IChatRendererContent, templateData: IChatListItemTemplate, context: IChatContentPartRenderContext, isProgressiveRender: boolean): IChatContentPart | undefined {
private renderChatContentPart(content: IChatRendererContent, templateData: IChatListItemTemplate, context: IChatContentPartRenderContext): IChatContentPart | undefined {
if (content.kind === 'treeData') {
return this.renderTreeData(content, templateData, context);
} else if (content.kind === 'progressMessage') {
Expand All @@ -782,7 +782,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
} else if (content.kind === 'warning') {
return this.instantiationService.createInstance(ChatWarningContentPart, 'warning', content.content, this.renderer);
} else if (content.kind === 'markdownContent') {
return this.renderMarkdown(content.content, templateData, context, isProgressiveRender);
return this.renderMarkdown(content.content, templateData, context);
} else if (content.kind === 'references') {
return this.renderContentReferencesListData(content, undefined, context, templateData);
} else if (content.kind === 'codeCitations') {
Expand Down Expand Up @@ -880,11 +880,11 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
return textEditPart;
}

private renderMarkdown(markdown: IMarkdownString, templateData: IChatListItemTemplate, context: IChatContentPartRenderContext, isProgressiveRender: boolean): IChatContentPart {
private renderMarkdown(markdown: IMarkdownString, templateData: IChatListItemTemplate, context: IChatContentPartRenderContext): IChatContentPart {
const element = context.element;
const fillInIncompleteTokens = isResponseVM(element) && (!element.isComplete || element.isCanceled || element.errorDetails?.responseIsFiltered || element.errorDetails?.responseIsIncomplete || !!element.renderData);
const codeBlockStartIndex = context.preceedingContentParts.reduce((acc, part) => acc + (part instanceof ChatMarkdownContentPart ? part.codeblocks.length : 0), 0);
const markdownPart = this.instantiationService.createInstance(ChatMarkdownContentPart, markdown, context, this._editorPool, fillInIncompleteTokens, codeBlockStartIndex, this.renderer, this._currentLayoutWidth, this.codeBlockModelCollection, this.rendererOptions, !isProgressiveRender);
const markdownPart = this.instantiationService.createInstance(ChatMarkdownContentPart, markdown, context, this._editorPool, fillInIncompleteTokens, codeBlockStartIndex, this.renderer, this._currentLayoutWidth, this.codeBlockModelCollection, this.rendererOptions);
const markdownPartId = markdownPart.id;
markdownPart.addDisposable(markdownPart.onDidChangeHeight(() => {
markdownPart.layout(this._currentLayoutWidth);
Expand Down

0 comments on commit 9944c35

Please sign in to comment.