-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathchildProcessAttachService.ts
More file actions
63 lines (56 loc) · 2.93 KB
/
childProcessAttachService.ts
File metadata and controls
63 lines (56 loc) · 2.93 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { debug, DebugConfiguration, DebugSession, DebugSessionOptions, l10n, WorkspaceFolder } from 'vscode';
import { captureTelemetry } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { AttachRequestArguments } from '../../types';
import { IChildProcessAttachService } from './types';
import { getWorkspaceFolders, showErrorMessage } from '../../common/vscodeapi';
import { noop } from '../../common/utils/misc';
import { traceLog } from '../../common/log/logging';
/**
* This class is responsible for attaching the debugger to any
* child processes launched. I.e. this is the class responsible for multi-proc debugging.
* @export
* @class ChildProcessAttachEventHandler
* @implements {IChildProcessAttachService}
*/
export class ChildProcessAttachService implements IChildProcessAttachService {
@captureTelemetry(EventName.DEBUGGER_ATTACH_TO_CHILD_PROCESS)
public async attach(data: AttachRequestArguments & DebugConfiguration, parentSession: DebugSession): Promise<void> {
const debugConfig: AttachRequestArguments & DebugConfiguration = { ...data };
// Remove the 'purpose' field from the child process debug configuration.
// The child session inherits the parent's configuration (including 'purpose')
// via debugpy's notify_of_subprocess. If the parent is a test debug session
// (purpose: ['debug-test']), the child would also appear to be a test session.
// This can cause the Python extension's test adapter to incorrectly treat the
// child process session termination as the end of the test run, which results
// in premature disconnection of the parent (test runner) debug session.
// See: https://github.com/microsoft/vscode-python-debugger/issues/548
delete debugConfig.purpose;
const debugSessionOption: DebugSessionOptions = {
parentSession: parentSession,
lifecycleManagedByParent: true,
};
const folder = this.getRelatedWorkspaceFolder(debugConfig);
traceLog('Start debugger in the attach child proccess');
const launched = await debug.startDebugging(folder, debugConfig, debugSessionOption);
if (!launched) {
showErrorMessage(l10n.t('Failed to launch debugger for child process {0}', debugConfig.subProcessId!)).then(
noop,
noop,
);
}
}
private getRelatedWorkspaceFolder(
config: AttachRequestArguments & DebugConfiguration,
): WorkspaceFolder | undefined {
const workspaceFolder = config.workspaceFolder;
const hasWorkspaceFolders = (getWorkspaceFolders()?.length || 0) > 0;
if (!hasWorkspaceFolders || !workspaceFolder) {
return;
}
return getWorkspaceFolders()!.find((ws) => ws.uri.fsPath === workspaceFolder);
}
}