Repository navigation
Expand file tree
/
Copy pathdebugCommands.ts
More file actions
58 lines (54 loc) · 2.62 KB
/
Copy pathdebugCommands.ts
File metadata and controls
58 lines (54 loc) · 2.62 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
// 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 { ILaunchJsonReader } from './configuration/types';
import { DebugPurpose, LaunchRequestArguments } from '../types';
@injectable()
export class DebugCommands implements IExtensionSingleActivationService {
constructor(
@inject(ICommandManager) private readonly commandManager: ICommandManager,
@inject(IDebugService) private readonly debugService: IDebugService,
@inject(ILaunchJsonReader) private readonly launchJsonReader: ILaunchJsonReader,
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
) {}
public activate(): Promise<void> {
this.disposables.push(
this.commandManager.registerCommand(Commands.Debug_In_Terminal, async (file: Uri) => {
sendTelemetryEvent(EventName.DEBUG_IN_TERMINAL_BUTTON);
const config = await this.getDebugConfiguration(file);
this.debugService.startDebugging(undefined, config);
}),
);
return Promise.resolve();
}
private async getDebugConfiguration(uri: Uri): Promise<DebugConfiguration> {
const configs = (await this.launchJsonReader.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;
}
// 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 ${path.basename(uri.fsPath)}`,
type: 'python',
request: 'launch',
program: uri.fsPath,
console: 'integratedTerminal',
};
}
}