forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugLauncher.ts
More file actions
63 lines (59 loc) · 2.24 KB
/
debugLauncher.ts
File metadata and controls
63 lines (59 loc) · 2.24 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
import * as os from 'os';
import { CancellationToken, debug, OutputChannel, workspace, Uri } from 'vscode';
import { PythonSettings } from '../../common/configSettings';
import { execPythonFile } from './../../common/utils';
import { createDeferred } from './../../common/helpers';
const pythonSettings = PythonSettings.getInstance();
export function launchDebugger(rootDirectory: string, testArgs: string[], token?: CancellationToken, outChannel?: OutputChannel) {
const def = createDeferred<any>();
const launchDef = createDeferred<any>();
let outputChannelShown = false;
execPythonFile(pythonSettings.pythonPath, testArgs, rootDirectory, true, (data: string) => {
if (data.startsWith('READY' + os.EOL)) {
// debug socket server has started.
launchDef.resolve();
data = data.substring(('READY' + os.EOL).length);
}
if (!outputChannelShown) {
outputChannelShown = true;
outChannel.show();
}
outChannel.append(data);
}, token).catch(reason => {
if (!def.rejected && !def.resolved) {
def.reject(reason);
}
}).then(() => {
if (!def.rejected && !def.resolved) {
def.resolve();
}
}).catch(reason => {
if (!def.rejected && !def.resolved) {
def.reject(reason);
}
});
launchDef.promise.then(() => {
if (!Array.isArray(workspace.workspaceFolders) || workspace.workspaceFolders.length === 0) {
throw new Error('Please open a workspace');
}
let workspaceFolder = workspace.getWorkspaceFolder(Uri.file(rootDirectory));
if (!workspaceFolder) {
workspaceFolder = workspace.workspaceFolders[0];
}
return debug.startDebugging(workspaceFolder, {
"name": "Debug Unit Test",
"type": "python",
"request": "attach",
"localRoot": rootDirectory,
"remoteRoot": rootDirectory,
"port": pythonSettings.unitTest.debugPort,
"secret": "my_secret",
"host": "localhost"
});
}).catch(reason => {
if (!def.rejected && !def.resolved) {
def.reject(reason);
}
});
return def.promise;
}