Path: blob/main/src/vs/workbench/contrib/chat/browser/chatContentParts/chatTaskContentPart.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as dom from '../../../../../base/browser/dom.js';6import { Event } from '../../../../../base/common/event.js';7import { Disposable, IDisposable } from '../../../../../base/common/lifecycle.js';8import { MarkdownRenderer } from '../../../../../editor/browser/widget/markdownRenderer/browser/markdownRenderer.js';9import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';10import { IChatProgressRenderableResponseContent } from '../../common/chatModel.js';11import { IChatTask, IChatTaskSerialized } from '../../common/chatService.js';12import { IChatContentPart, IChatContentPartRenderContext } from './chatContentParts.js';13import { ChatProgressContentPart } from './chatProgressContentPart.js';14import { ChatCollapsibleListContentPart, CollapsibleListPool } from './chatReferencesContentPart.js';1516export class ChatTaskContentPart extends Disposable implements IChatContentPart {17public readonly domNode: HTMLElement;18public readonly onDidChangeHeight: Event<void>;1920private isSettled: boolean;2122constructor(23private readonly task: IChatTask | IChatTaskSerialized,24contentReferencesListPool: CollapsibleListPool,25renderer: MarkdownRenderer,26context: IChatContentPartRenderContext,27@IInstantiationService instantiationService: IInstantiationService,28) {29super();3031if (task.progress.length) {32this.isSettled = true;33const refsPart = this._register(instantiationService.createInstance(ChatCollapsibleListContentPart, task.progress, task.content.value, context, contentReferencesListPool));34this.domNode = dom.$('.chat-progress-task');35this.domNode.appendChild(refsPart.domNode);36this.onDidChangeHeight = refsPart.onDidChangeHeight;37} else {38const isSettled = task.kind === 'progressTask' ?39task.isSettled() :40true;41this.isSettled = isSettled;42const showSpinner = !isSettled && !context.element.isComplete;43const progressPart = this._register(instantiationService.createInstance(ChatProgressContentPart, task, renderer, context, showSpinner, true, undefined));44this.domNode = progressPart.domNode;45this.onDidChangeHeight = Event.None;46}47}4849hasSameContent(other: IChatProgressRenderableResponseContent): boolean {50if (51other.kind === 'progressTask' &&52this.task.kind === 'progressTask' &&53other.isSettled() !== this.isSettled54) {55return false;56}5758return other.kind === this.task.kind &&59other.progress.length === this.task.progress.length;60}6162addDisposable(disposable: IDisposable): void {63this._register(disposable);64}65}666768