Path: blob/main/extensions/copilot/src/extension/context/node/resolvers/inlineFixIntentInvocation.ts
13405 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*--------------------------------------------------------------------------------------------*/456import { BasePromptElementProps } from '@vscode/prompt-tsx';7import type { CancellationToken, ChatResponseProgressPart, ChatResponseReferencePart, ChatResponseStream, ChatResult, Progress } from 'vscode';8import { IResponsePart } from '../../../../platform/chat/common/chatMLFetcher';9import { ChatLocation } from '../../../../platform/chat/common/commonTypes';10import { IChatEndpoint } from '../../../../platform/networking/common/networking';11import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation';12import { IBuildPromptContext } from '../../../prompt/common/intents';13import { IDocumentContext } from '../../../prompt/node/documentContext';14import { IIntent, IIntentInvocation, IResponseProcessorContext, NoopReplyInterpreter, ReplyInterpreter, ReplyInterpreterMetaData } from '../../../prompt/node/intents';15import { PromptElementCtor } from '../../../prompts/node/base/promptElement';16import { PromptRenderer } from '../../../prompts/node/base/promptRenderer';1718export class InlineFixIntentInvocation implements IIntentInvocation {1920private replyInterpreter: ReplyInterpreter | null = null;2122constructor(23readonly intent: IIntent,24readonly location: ChatLocation,25readonly endpoint: IChatEndpoint,26private readonly prompt: PromptElementCtor<InlineFixProps, unknown>,27private readonly documentContext: IDocumentContext,28private readonly features: IInlineFixFeatures,29@IInstantiationService private readonly instantiationService: IInstantiationService,30) { }3132async buildPrompt(33promptContext: IBuildPromptContext,34progress: Progress<ChatResponseReferencePart | ChatResponseProgressPart>,35token: CancellationToken36) {37const renderer = PromptRenderer.create(this.instantiationService, this.endpoint, this.prompt, {38documentContext: this.documentContext,39promptContext,40features: this.features,41});42const result = await renderer.render(progress, token);43this.replyInterpreter = result.metadata.get(ReplyInterpreterMetaData)?.replyInterpreter ?? (result.hasIgnoredFiles ? new NoopReplyInterpreter() : null);44return result;45}4647processResponse(context: IResponseProcessorContext, inputStream: AsyncIterable<IResponsePart>, outputStream: ChatResponseStream, token: CancellationToken): Promise<ChatResult | void> {48if (!this.replyInterpreter) {49throw new Error('Could not process response without a reply interpreter.');50}51return this.replyInterpreter.processResponse(context, inputStream, outputStream, token);52}53}5455export interface IInlineFixFeatures {56readonly useWorkspaceChunksFromSelection: boolean;57readonly useWorkspaceChunksFromDiagnostics: boolean;58}5960export interface InlineFixProps extends BasePromptElementProps {61readonly documentContext: IDocumentContext;62readonly promptContext: IBuildPromptContext;63readonly features: IInlineFixFeatures;64}656667