Path: blob/main/extensions/copilot/src/extension/intents/node/fixIntent.ts
13399 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 l10n from '@vscode/l10n';6import { ChatLocation } from '../../../platform/chat/common/commonTypes';7import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';8import { isNotebookCellOrNotebookChatInput } from '../../../util/common/notebooks';9import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';10import { Intent } from '../../common/constants';11import { GenericPanelIntentInvocation } from '../../context/node/resolvers/genericPanelIntentInvocation';12import { IInlineFixFeatures, InlineFixIntentInvocation, InlineFixProps } from '../../context/node/resolvers/inlineFixIntentInvocation';13import { IIntent, IIntentInvocation, IIntentInvocationContext, IIntentSlashCommandInfo } from '../../prompt/node/intents';14import { PromptElementCtor } from '../../prompts/node/base/promptElement';15import { InlineFix3Prompt } from '../../prompts/node/inline/inlineChatFix3Prompt';16import { InlineFixNotebookPrompt } from '../../prompts/node/inline/inlineChatNotebookFixPrompt';17import { PanelChatFixPrompt } from '../../prompts/node/panel/panelChatFixPrompt';18import { ContributedToolName } from '../../tools/common/toolNames';192021export class FixIntent implements IIntent {2223static readonly ID = Intent.Fix;24readonly id = Intent.Fix;25readonly locations = [ChatLocation.Editor, ChatLocation.Panel, ChatLocation.Notebook];26readonly description = l10n.t('Propose a fix for the problems in the selected code');2728readonly commandInfo: IIntentSlashCommandInfo = { toolEquivalent: ContributedToolName.GetErrors };2930constructor(31@IInstantiationService private readonly instantiationService: IInstantiationService,32@IEndpointProvider private readonly endpointProvider: IEndpointProvider,33) { }3435async invoke(invocationContext: IIntentInvocationContext): Promise<IIntentInvocation> {36const { location, documentContext, request } = invocationContext;37if (!documentContext) {38throw new Error('Open a file to fix an issue');39}4041if (location === ChatLocation.Panel) {42const endpoint = await this.endpointProvider.getChatEndpoint(request);43return this.instantiationService.createInstance(GenericPanelIntentInvocation, this, location, endpoint, PanelChatFixPrompt, invocationContext.documentContext);44}45const attempt = request.attempt;46const endpoint = await this.endpointProvider.getChatEndpoint(request);4748let prompt: PromptElementCtor<InlineFixProps, unknown>;49if (isNotebookCellOrNotebookChatInput(documentContext.document.uri)) {50prompt = InlineFixNotebookPrompt;51} else {52prompt = InlineFix3Prompt;53}5455const useWorkspaceChunksOnRetry = attempt > 1;56const features: IInlineFixFeatures = {57useWorkspaceChunksFromSelection: useWorkspaceChunksOnRetry,58useWorkspaceChunksFromDiagnostics: false59};60return this.instantiationService.createInstance(InlineFixIntentInvocation, this, location, endpoint, prompt, documentContext, features);61}62}636465