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