forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugCommands.ts
More file actions
73 lines (68 loc) · 3.56 KB
/
debugCommands.ts
File metadata and controls
73 lines (68 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as path from 'path';
import { inject, injectable } from 'inversify';
import { DebugConfiguration, Uri } from 'vscode';
import { IExtensionSingleActivationService } from '../../activation/types';
import { ICommandManager, IDebugService } from '../../common/application/types';
import { Commands } from '../../common/constants';
import { IDisposableRegistry } from '../../common/types';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { DebugPurpose, LaunchRequestArguments } from '../types';
import { IInterpreterService } from '../../interpreter/contracts';
import { noop } from '../../common/utils/misc';
import { getConfigurationsByUri } from './configuration/launch.json/launchJsonReader';
import {
CreateEnvironmentCheckKind,
triggerCreateEnvironmentCheckNonBlocking,
} from '../../pythonEnvironments/creation/createEnvironmentTrigger';
@injectable()
export class DebugCommands implements IExtensionSingleActivationService {
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: false };
constructor(
@inject(ICommandManager) private readonly commandManager: ICommandManager,
@inject(IDebugService) private readonly debugService: IDebugService,
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
) {}
public activate(): Promise<void> {
this.disposables.push(
this.commandManager.registerCommand(Commands.Debug_In_Terminal, async (file?: Uri) => {
sendTelemetryEvent(EventName.DEBUG_IN_TERMINAL_BUTTON);
const interpreter = await this.interpreterService.getActiveInterpreter(file);
if (!interpreter) {
this.commandManager.executeCommand(Commands.TriggerEnvironmentSelection, file).then(noop, noop);
return;
}
sendTelemetryEvent(EventName.ENVIRONMENT_CHECK_TRIGGER, undefined, { trigger: 'debug-in-terminal' });
triggerCreateEnvironmentCheckNonBlocking(CreateEnvironmentCheckKind.File, file);
const config = await DebugCommands.getDebugConfiguration(file);
this.debugService.startDebugging(undefined, config);
}),
);
return Promise.resolve();
}
private static async getDebugConfiguration(uri?: Uri): Promise<DebugConfiguration> {
const configs = (await getConfigurationsByUri(uri)).filter((c) => c.request === 'launch');
for (const config of configs) {
if ((config as LaunchRequestArguments).purpose?.includes(DebugPurpose.DebugInTerminal)) {
if (!config.program && !config.module && !config.code) {
// This is only needed if people reuse debug-test for debug-in-terminal
config.program = uri?.fsPath ?? '${file}';
}
// Ensure that the purpose is cleared, this is so we can track if people accidentally
// trigger this via F5 or Start with debugger.
config.purpose = [];
return config;
}
}
return {
name: `Debug ${uri ? path.basename(uri.fsPath) : 'File'}`,
type: 'python',
request: 'launch',
program: uri?.fsPath ?? '${file}',
console: 'integratedTerminal',
};
}
}