Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/intents/node/fixIntent.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 { isNotebookCellOrNotebookChatInput } from '../../../util/common/notebooks';
10
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
11
import { Intent } from '../../common/constants';
12
import { GenericPanelIntentInvocation } from '../../context/node/resolvers/genericPanelIntentInvocation';
13
import { IInlineFixFeatures, InlineFixIntentInvocation, InlineFixProps } from '../../context/node/resolvers/inlineFixIntentInvocation';
14
import { IIntent, IIntentInvocation, IIntentInvocationContext, IIntentSlashCommandInfo } from '../../prompt/node/intents';
15
import { PromptElementCtor } from '../../prompts/node/base/promptElement';
16
import { InlineFix3Prompt } from '../../prompts/node/inline/inlineChatFix3Prompt';
17
import { InlineFixNotebookPrompt } from '../../prompts/node/inline/inlineChatNotebookFixPrompt';
18
import { PanelChatFixPrompt } from '../../prompts/node/panel/panelChatFixPrompt';
19
import { ContributedToolName } from '../../tools/common/toolNames';
20
21
22
export class FixIntent implements IIntent {
23
24
static readonly ID = Intent.Fix;
25
readonly id = Intent.Fix;
26
readonly locations = [ChatLocation.Editor, ChatLocation.Panel, ChatLocation.Notebook];
27
readonly description = l10n.t('Propose a fix for the problems in the selected code');
28
29
readonly commandInfo: IIntentSlashCommandInfo = { toolEquivalent: ContributedToolName.GetErrors };
30
31
constructor(
32
@IInstantiationService private readonly instantiationService: IInstantiationService,
33
@IEndpointProvider private readonly endpointProvider: IEndpointProvider,
34
) { }
35
36
async invoke(invocationContext: IIntentInvocationContext): Promise<IIntentInvocation> {
37
const { location, documentContext, request } = invocationContext;
38
if (!documentContext) {
39
throw new Error('Open a file to fix an issue');
40
}
41
42
if (location === ChatLocation.Panel) {
43
const endpoint = await this.endpointProvider.getChatEndpoint(request);
44
return this.instantiationService.createInstance(GenericPanelIntentInvocation, this, location, endpoint, PanelChatFixPrompt, invocationContext.documentContext);
45
}
46
const attempt = request.attempt;
47
const endpoint = await this.endpointProvider.getChatEndpoint(request);
48
49
let prompt: PromptElementCtor<InlineFixProps, unknown>;
50
if (isNotebookCellOrNotebookChatInput(documentContext.document.uri)) {
51
prompt = InlineFixNotebookPrompt;
52
} else {
53
prompt = InlineFix3Prompt;
54
}
55
56
const useWorkspaceChunksOnRetry = attempt > 1;
57
const features: IInlineFixFeatures = {
58
useWorkspaceChunksFromSelection: useWorkspaceChunksOnRetry,
59
useWorkspaceChunksFromDiagnostics: false
60
};
61
return this.instantiationService.createInstance(InlineFixIntentInvocation, this, location, endpoint, prompt, documentContext, features);
62
}
63
}
64
65