Skip to content

Commit d45970e

Browse files
Adopt lifecycle managed by parent (#32)
1 parent d1f0aff commit d45970e

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/extension/debugger/hooks/childProcessAttachService.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
'use strict';
55

6-
import { debug, DebugConfiguration, DebugSession, l10n, WorkspaceFolder } from 'vscode';
6+
import { debug, DebugConfiguration, DebugSession, DebugSessionOptions, l10n, WorkspaceFolder } from 'vscode';
77
import { captureTelemetry } from '../../telemetry';
88
import { EventName } from '../../telemetry/constants';
99
import { AttachRequestArguments } from '../../types';
@@ -22,11 +22,17 @@ export class ChildProcessAttachService implements IChildProcessAttachService {
2222
@captureTelemetry(EventName.DEBUGGER_ATTACH_TO_CHILD_PROCESS)
2323
public async attach(data: AttachRequestArguments & DebugConfiguration, parentSession: DebugSession): Promise<void> {
2424
const debugConfig: AttachRequestArguments & DebugConfiguration = data;
25-
const processId = debugConfig.subProcessId!;
25+
const debugSessionOption: DebugSessionOptions = {
26+
parentSession: parentSession,
27+
lifecycleManagedByParent: true,
28+
};
2629
const folder = this.getRelatedWorkspaceFolder(debugConfig);
27-
const launched = await debug.startDebugging(folder, debugConfig, parentSession);
30+
const launched = await debug.startDebugging(folder, debugConfig, debugSessionOption);
2831
if (!launched) {
29-
showErrorMessage(l10n.t('Failed to launch debugger for child process {0}', processId)).then(noop, noop);
32+
showErrorMessage(l10n.t('Failed to launch debugger for child process {0}', debugConfig.subProcessId!)).then(
33+
noop,
34+
noop,
35+
);
3036
}
3137
}
3238

src/test/unittest/hooks/childProcessAttachService.unit.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ suite('Debug - Attach to Child Process', () => {
113113
sinon.assert.calledOnceWithExactly(startDebuggingStub, undefined, sinon.match.any, sinon.match.any);
114114
sinon.assert.notCalled(showErrorMessageStub);
115115
});
116-
test('Validate debug config is passed as is', async () => {
116+
test('Validate debug config is passed with the correct params', async () => {
117117
const data: LaunchRequestArguments | AttachRequestArguments = {
118118
request: 'attach',
119119
type: 'debugpy',
@@ -136,7 +136,7 @@ suite('Debug - Attach to Child Process', () => {
136136
sinon.assert.calledOnceWithExactly(startDebuggingStub, undefined, sinon.match.any, sinon.match.any);
137137
const [, secondArg, thirdArg] = startDebuggingStub.args[0];
138138
expect(secondArg).to.deep.equal(debugConfig);
139-
expect(thirdArg).to.deep.equal(session);
139+
expect(thirdArg).to.deep.equal({ parentSession: session, lifecycleManagedByParent: true });
140140
sinon.assert.notCalled(showErrorMessageStub);
141141
});
142142
test('Pass data as is if data is attach debug configuration', async () => {
@@ -157,7 +157,7 @@ suite('Debug - Attach to Child Process', () => {
157157
sinon.assert.calledOnceWithExactly(startDebuggingStub, undefined, sinon.match.any, sinon.match.any);
158158
const [, secondArg, thirdArg] = startDebuggingStub.args[0];
159159
expect(secondArg).to.deep.equal(debugConfig);
160-
expect(thirdArg).to.deep.equal(session);
160+
expect(thirdArg).to.deep.equal({ parentSession: session, lifecycleManagedByParent: true });
161161
sinon.assert.notCalled(showErrorMessageStub);
162162
});
163163
test('Validate debug config when parent/root parent was attached', async () => {
@@ -185,7 +185,7 @@ suite('Debug - Attach to Child Process', () => {
185185
sinon.assert.calledOnceWithExactly(startDebuggingStub, undefined, sinon.match.any, sinon.match.any);
186186
const [, secondArg, thirdArg] = startDebuggingStub.args[0];
187187
expect(secondArg).to.deep.equal(debugConfig);
188-
expect(thirdArg).to.deep.equal(session);
188+
expect(thirdArg).to.deep.equal({ parentSession: session, lifecycleManagedByParent: true });
189189
sinon.assert.notCalled(showErrorMessageStub);
190190
});
191191
});

0 commit comments

Comments
 (0)