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