Path: blob/main/extensions/copilot/src/extension/intents/node/generateCodeIntent.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 { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';9import { Intent } from '../../common/constants';10import { GenericInlineIntentInvocation } from '../../context/node/resolvers/genericInlineIntentInvocation';11import { EditStrategy } from '../../prompt/node/editGeneration';12import { IIntent, IIntentInvocation, IIntentInvocationContext, IIntentSlashCommandInfo } from '../../prompt/node/intents';131415export class GenerateCodeIntent implements IIntent {1617static readonly ID = Intent.Generate;1819readonly id = GenerateCodeIntent.ID;20readonly description = l10n.t('Generate new code');21readonly locations = [ChatLocation.Editor];22readonly commandInfo: IIntentSlashCommandInfo = { hiddenFromUser: true };2324constructor(25@IInstantiationService private readonly instantiationService: IInstantiationService,26@IEndpointProvider private readonly endpointProvider: IEndpointProvider,27) { }2829async invoke(invocationContext: IIntentInvocationContext): Promise<IIntentInvocation> {30const { location, documentContext, request } = invocationContext;31if (!documentContext) {32throw new Error('Open a file to add code.');33}34const endpoint = await this.endpointProvider.getChatEndpoint(request);35return this.instantiationService.createInstance(GenericInlineIntentInvocation, this, location, endpoint, documentContext, EditStrategy.ForceInsertion);36}37}383940