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