Path: blob/main/extensions/copilot/src/util/common/test/mockChatResponseStream.ts
13401 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 type * as vscode from 'vscode';6import { ChatResponseAnchorPart, ChatResponseCommandButtonPart, ChatResponseConfirmationPart, ChatResponseExternalEditPart, ChatResponseFileTreePart, ChatResponseMarkdownPart } from '../../../vscodeTypes';7import { coalesce } from '../../vs/base/common/arrays';8import { ChatResponseStreamImpl } from '../chatResponseStreamImpl';9import { isLocation, isSymbolInformation, isUri } from '../types';1011export class SpyChatResponseStream extends ChatResponseStreamImpl {1213items: vscode.ExtendedChatResponsePart[] = [];1415get currentProgress(): string {16return coalesce(this.items17.map((part): string | undefined => {18if (part instanceof ChatResponseMarkdownPart) {19return part.value.value;20}2122if (part instanceof ChatResponseAnchorPart) {23if (isUri(part.value)) {24return part.value.toString();25} else if (isLocation(part.value)) {26return part.value.uri.toString();27} else if (isSymbolInformation(part.value2)) {28return part.value2.name;29}30}3132return undefined;33})).join('');34}3536get confirmations(): vscode.ChatResponseConfirmationPart[] {37return this.items.filter((part) => part instanceof ChatResponseConfirmationPart);38}3940get fileTrees(): vscode.ChatResponseFileTreePart[] {41return this.items.filter((part) => part instanceof ChatResponseFileTreePart);42}4344get commandButtons(): vscode.Command[] {45return this.items.filter((part): part is ChatResponseCommandButtonPart => part instanceof ChatResponseCommandButtonPart).map(part => part.value);46}4748get externalEditUris(): vscode.Uri[] {49return this.items50.filter((part): part is ChatResponseExternalEditPart => part instanceof ChatResponseExternalEditPart)51.flatMap(part => part.uris);52}5354constructor() {55super((part) => this.items.push(part), () => { }, undefined, undefined, undefined, () => Promise.resolve(undefined));56}5758override async externalEdit(target: vscode.Uri | vscode.Uri[], callback: () => Thenable<unknown>): Promise<string> {59const uris = Array.isArray(target) ? target : [target];60this.items.push(new ChatResponseExternalEditPart(uris, callback));61await callback();62return '';63}64}656667