Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompt/vscode-node/debugCommands.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 vscode from 'vscode';
7
import { ITasksService } from '../../../platform/tasks/common/tasksService';
8
import { Disposable } from '../../../util/vs/base/common/lifecycle';
9
import { URI } from '../../../util/vs/base/common/uri';
10
import { generateSTest } from '../../conversation/vscode-node/feedbackReporter';
11
import { IConversationStore } from '../../conversationStore/node/conversationStore';
12
import { ILaunchConfigService, needsWorkspaceFolderForTaskError } from '../../onboardDebug/common/launchConfigService';
13
import { IStartDebuggingParsedResponse } from '../../onboardDebug/node/parseLaunchConfigFromResponse';
14
import { IFeedbackReporter } from '../node/feedbackReporter';
15
16
export class DebugCommandsContribution extends Disposable {
17
constructor(
18
@IConversationStore private readonly _conversationStore: IConversationStore,
19
@ILaunchConfigService private readonly launchConfigService: ILaunchConfigService,
20
@IFeedbackReporter private readonly feedbackReporter: IFeedbackReporter,
21
@ITasksService private readonly tasksService: ITasksService,
22
) {
23
super();
24
25
this._register(vscode.commands.registerCommand('github.copilot.debug.generateSTest', async () => {
26
if (!this.feedbackReporter.canReport) {
27
return;
28
}
29
const lastTurn = this._conversationStore.lastConversation?.getLatestTurn();
30
if (lastTurn) {
31
const sTestValue = await generateSTest(lastTurn);
32
if (sTestValue) {
33
vscode.env.clipboard.writeText(sTestValue.join('\n'));
34
vscode.window.showInformationMessage('STest copied to clipboard');
35
}
36
}
37
}));
38
const ensureTask = async (workspaceFolder: URI | undefined, config: IStartDebuggingParsedResponse) => {
39
const wf = workspaceFolder || vscode.workspace.workspaceFolders?.[0].uri;
40
if (!wf) {
41
vscode.window.showErrorMessage(needsWorkspaceFolderForTaskError());
42
return;
43
}
44
45
if (config.tasks?.length) {
46
await this.tasksService.ensureTask(wf, config.tasks[0]);
47
}
48
};
49
50
this._register(vscode.commands.registerCommand('github.copilot.createLaunchJsonFileWithContents', async (launchConfig: IStartDebuggingParsedResponse) => {
51
// Define the path for the .vscode/launch.json file
52
const workspaceFolders = vscode.workspace.workspaceFolders;
53
if (!workspaceFolders?.length) {
54
vscode.window.showErrorMessage('No workspace folder is open.');
55
return;
56
}
57
58
await ensureTask(workspaceFolders[0].uri, launchConfig);
59
await launchConfigService.add(workspaceFolders[0].uri, launchConfig);
60
await launchConfigService.show(workspaceFolders[0].uri, launchConfig.configurations[0].name);
61
}));
62
this._register((vscode.commands.registerCommand('github.copilot.startDebugging', async (config: IStartDebuggingParsedResponse, progress) => {
63
const result = await this.launchConfigService.resolveConfigurationInputs(config);
64
if (result?.config) {
65
await ensureTask(undefined, config);
66
await this.launchConfigService.launch(result?.config);
67
progress.progress(vscode.l10n.t('Started debugging {0}', result.config.name));
68
return;
69
} else {
70
progress.markdown(vscode.l10n.t('Could not start debugging. Please try again.'));
71
return;
72
}
73
})));
74
}
75
}
76
77