Path: blob/main/extensions/copilot/src/extension/onboardDebug/vscode-node/onboardTerminalTestsContribution.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 { Disposable } from '../../../util/vs/base/common/lifecycle';7import { IDebuggableCommandIdentifier } from '../node/debuggableCommandIdentifier';8import { COPILOT_DEBUG_COMMAND } from './copilotDebugCommandContribution';910const PROVIDER_ID = 'copilot-chat.terminalToDebugging';11const PROVIDER_ID2 = 'copilot-chat.terminalToDebuggingSuccess';1213export class OnboardTerminalTestsContribution extends Disposable implements vscode.TerminalQuickFixProvider {14/**15* Execution end events for terminals. This is a hacky back door to get16* output info into quick fixes.17*/18private lastExecutionFor = new Map<vscode.Terminal, vscode.TerminalShellExecutionStartEvent>();1920constructor(21@IDebuggableCommandIdentifier private readonly debuggableCommandIdentifier: IDebuggableCommandIdentifier,22) {23super();24this._register(vscode.window.registerTerminalQuickFixProvider(PROVIDER_ID, this));25this._register(vscode.window.registerTerminalQuickFixProvider(PROVIDER_ID2, this));26this._register(vscode.window.onDidCloseTerminal(e => {27this.lastExecutionFor.delete(e);28}));29this._register(vscode.window.onDidStartTerminalShellExecution(e => {30this.lastExecutionFor.set(e.terminal, e);31}));32this._register(vscode.commands.registerCommand('github.copilot.chat.rerunWithCopilotDebug', () => {33const terminal = vscode.window.activeTerminal;34const execution = terminal && this.lastExecutionFor.get(terminal);35if (!execution) {36return;37}3839terminal.sendText(`${COPILOT_DEBUG_COMMAND} ${execution.execution.commandLine.value}`, true);40}));41}4243async provideTerminalQuickFixes(44commandMatchResult: vscode.TerminalCommandMatchResult,45token: vscode.CancellationToken46): Promise<undefined | vscode.TerminalQuickFixTerminalCommand> {47const activeTerminal = vscode.window.activeTerminal?.shellIntegration;48const cwd = activeTerminal?.cwd;49if (!await this.debuggableCommandIdentifier.isDebuggable(cwd, commandMatchResult.commandLine, token)) {50return undefined;51}5253// todo@connor4312: try to parse stack trace and shell intergation and54// set a breakpoint on any failure position55return {56terminalCommand: `${COPILOT_DEBUG_COMMAND} ${commandMatchResult.commandLine}`,57shouldExecute: false,58};59}60}616263