Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/intents/node/generateCodeIntent.ts
13399 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 * as l10n from '@vscode/l10n';
7
import { ChatLocation } from '../../../platform/chat/common/commonTypes';
8
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';
9
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
10
import { Intent } from '../../common/constants';
11
import { GenericInlineIntentInvocation } from '../../context/node/resolvers/genericInlineIntentInvocation';
12
import { EditStrategy } from '../../prompt/node/editGeneration';
13
import { IIntent, IIntentInvocation, IIntentInvocationContext, IIntentSlashCommandInfo } from '../../prompt/node/intents';
14
15
16
export class GenerateCodeIntent implements IIntent {
17
18
static readonly ID = Intent.Generate;
19
20
readonly id = GenerateCodeIntent.ID;
21
readonly description = l10n.t('Generate new code');
22
readonly locations = [ChatLocation.Editor];
23
readonly commandInfo: IIntentSlashCommandInfo = { hiddenFromUser: true };
24
25
constructor(
26
@IInstantiationService private readonly instantiationService: IInstantiationService,
27
@IEndpointProvider private readonly endpointProvider: IEndpointProvider,
28
) { }
29
30
async invoke(invocationContext: IIntentInvocationContext): Promise<IIntentInvocation> {
31
const { location, documentContext, request } = invocationContext;
32
if (!documentContext) {
33
throw new Error('Open a file to add code.');
34
}
35
const endpoint = await this.endpointProvider.getChatEndpoint(request);
36
return this.instantiationService.createInstance(GenericInlineIntentInvocation, this, location, endpoint, documentContext, EditStrategy.ForceInsertion);
37
}
38
}
39
40