Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/util/common/test/mockChatResponseStream.ts
13401 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 type * as vscode from 'vscode';
7
import { ChatResponseAnchorPart, ChatResponseCommandButtonPart, ChatResponseConfirmationPart, ChatResponseExternalEditPart, ChatResponseFileTreePart, ChatResponseMarkdownPart } from '../../../vscodeTypes';
8
import { coalesce } from '../../vs/base/common/arrays';
9
import { ChatResponseStreamImpl } from '../chatResponseStreamImpl';
10
import { isLocation, isSymbolInformation, isUri } from '../types';
11
12
export class SpyChatResponseStream extends ChatResponseStreamImpl {
13
14
items: vscode.ExtendedChatResponsePart[] = [];
15
16
get currentProgress(): string {
17
return coalesce(this.items
18
.map((part): string | undefined => {
19
if (part instanceof ChatResponseMarkdownPart) {
20
return part.value.value;
21
}
22
23
if (part instanceof ChatResponseAnchorPart) {
24
if (isUri(part.value)) {
25
return part.value.toString();
26
} else if (isLocation(part.value)) {
27
return part.value.uri.toString();
28
} else if (isSymbolInformation(part.value2)) {
29
return part.value2.name;
30
}
31
}
32
33
return undefined;
34
})).join('');
35
}
36
37
get confirmations(): vscode.ChatResponseConfirmationPart[] {
38
return this.items.filter((part) => part instanceof ChatResponseConfirmationPart);
39
}
40
41
get fileTrees(): vscode.ChatResponseFileTreePart[] {
42
return this.items.filter((part) => part instanceof ChatResponseFileTreePart);
43
}
44
45
get commandButtons(): vscode.Command[] {
46
return this.items.filter((part): part is ChatResponseCommandButtonPart => part instanceof ChatResponseCommandButtonPart).map(part => part.value);
47
}
48
49
get externalEditUris(): vscode.Uri[] {
50
return this.items
51
.filter((part): part is ChatResponseExternalEditPart => part instanceof ChatResponseExternalEditPart)
52
.flatMap(part => part.uris);
53
}
54
55
constructor() {
56
super((part) => this.items.push(part), () => { }, undefined, undefined, undefined, () => Promise.resolve(undefined));
57
}
58
59
override async externalEdit(target: vscode.Uri | vscode.Uri[], callback: () => Thenable<unknown>): Promise<string> {
60
const uris = Array.isArray(target) ? target : [target];
61
this.items.push(new ChatResponseExternalEditPart(uris, callback));
62
await callback();
63
return '';
64
}
65
}
66
67