forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingleFileDebug.ts
More file actions
50 lines (43 loc) · 1.79 KB
/
singleFileDebug.ts
File metadata and controls
50 lines (43 loc) · 1.79 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
import * as vscode from 'vscode';
import { dirname, join } from 'path';
export function activateSingleFileDebug() {
return vscode.commands.registerCommand('python.python-debug.startSession', config => {
if (!config.request) { // if 'request' is missing interpret this as a missing launch.json
config.type = 'python';
config.name = 'Launch';
config.request = 'launch';
config.pythonPath = "python";
config.debugOptions = [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
];
config.stopOnEntry = true;
config.module = '';
config.args = [];
config.console = "none";
config.exceptionHandling = [];
config.env = null;
if (vscode.workspace.rootPath) {
config.cwd = vscode.workspace.rootPath;
}
if (!config.program) {
const editor = vscode.window.activeTextEditor;
if (editor && editor.document.languageId === 'python') {
config.program = editor.document.fileName;
}
}
if (!config.cwd && config.program) {
// fall back if 'cwd' not known: derive it from 'program'
config.cwd = dirname(config.program);
}
if (vscode.workspace && vscode.workspace.rootPath) {
config.envFile = join(vscode.workspace.rootPath, '.env');
}
if (!config.envFile && typeof config.cwd === 'string' && config.cwd.lengths > 0){
config.envFile = join(config.cwd, '.env');
}
}
vscode.commands.executeCommand('vscode.startDebug', config);
});
}