Skip to content

Commit

Permalink
fix debug restart
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd committed Nov 13, 2024
1 parent 654f95b commit 44df949
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/client/common/application/debugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DebugConsole,
DebugSession,
DebugSessionCustomEvent,
DebugSessionOptions,
Disposable,
Event,
WorkspaceFolder,
Expand Down Expand Up @@ -57,7 +58,7 @@ export class DebugService implements IDebugService {
public startDebugging(
folder: WorkspaceFolder | undefined,
nameOrConfiguration: string | DebugConfiguration,
parentSession?: DebugSession,
parentSession?: DebugSession | DebugSessionOptions,
): Thenable<boolean> {
return debug.startDebugging(folder, nameOrConfiguration, parentSession);
}
Expand Down
10 changes: 7 additions & 3 deletions src/client/testing/common/debugLauncher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable, named } from 'inversify';
import * as path from 'path';
import { DebugConfiguration, l10n, Uri, WorkspaceFolder, DebugSession } from 'vscode';
import { DebugConfiguration, l10n, Uri, WorkspaceFolder, DebugSession, DebugSessionOptions } from 'vscode';
import { IApplicationShell, IDebugService } from '../../common/application/types';
import { EXTENSION_ROOT_DIR } from '../../common/constants';
import * as internalScripts from '../../common/process/internal/scripts';
Expand Down Expand Up @@ -32,7 +32,11 @@ export class DebugLauncher implements ITestDebugLauncher {
this.configService = this.serviceContainer.get<IConfigurationService>(IConfigurationService);
}

public async launchDebugger(options: LaunchOptions, callback?: () => void): Promise<void> {
public async launchDebugger(
options: LaunchOptions,
callback?: () => void,
sessionOptions?: DebugSessionOptions,
): Promise<void> {
const deferred = createDeferred<void>();
let hasCallbackBeenCalled = false;
if (options.token && options.token.isCancellationRequested) {
Expand All @@ -57,7 +61,7 @@ export class DebugLauncher implements ITestDebugLauncher {
const debugManager = this.serviceContainer.get<IDebugService>(IDebugService);

let activatedDebugSession: DebugSession | undefined;
debugManager.startDebugging(workspaceFolder, launchArgs).then(() => {
debugManager.startDebugging(workspaceFolder, launchArgs, sessionOptions).then(() => {
// Save the debug session after it is started so we can check if it is the one that was terminated.
activatedDebugSession = debugManager.activeDebugSession;
});
Expand Down
4 changes: 2 additions & 2 deletions src/client/testing/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CancellationToken, Disposable, OutputChannel, Uri } from 'vscode';
import { CancellationToken, DebugSessionOptions, Disposable, OutputChannel, Uri } from 'vscode';
import { Product } from '../../common/types';
import { TestSettingsPropertyNames } from '../configuration/types';
import { TestProvider } from '../types';
Expand Down Expand Up @@ -89,7 +89,7 @@ export interface ITestConfigurationManagerFactory {
}
export const ITestDebugLauncher = Symbol('ITestDebugLauncher');
export interface ITestDebugLauncher {
launchDebugger(options: LaunchOptions, callback?: () => void): Promise<void>;
launchDebugger(options: LaunchOptions, callback?: () => void, sessionOptions?: DebugSessionOptions): Promise<void>;
}

export const IUnitTestSocketServer = Symbol('IUnitTestSocketServer');
Expand Down
15 changes: 11 additions & 4 deletions src/client/testing/testController/pytest/pytestExecutionAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { CancellationTokenSource, TestRun, TestRunProfileKind, Uri } from 'vscode';
import { CancellationTokenSource, DebugSessionOptions, TestRun, TestRunProfileKind, Uri } from 'vscode';
import * as path from 'path';
import { ChildProcess } from 'child_process';
import { IConfigurationService, ITestOutputChannel } from '../../../common/types';
Expand Down Expand Up @@ -167,10 +167,17 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
runTestIdsPort: testIdsFileName,
pytestPort: resultNamedPipeName,
};
const sessionOptions: DebugSessionOptions = {
testRun: runInstance,
};
traceInfo(`Running DEBUG pytest with arguments: ${testArgs} for workspace ${uri.fsPath} \r\n`);
await debugLauncher!.launchDebugger(launchOptions, () => {
serverCancel.cancel();
});
await debugLauncher!.launchDebugger(
launchOptions,
() => {
serverCancel.cancel();
},
sessionOptions,
);
} else {
// deferredTillExecClose is resolved when all stdout and stderr is read
const deferredTillExecClose: Deferred<void> = utils.createTestingDeferred();
Expand Down
15 changes: 11 additions & 4 deletions src/client/testing/testController/unittest/testExecutionAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import * as path from 'path';
import { CancellationTokenSource, TestRun, TestRunProfileKind, Uri } from 'vscode';
import { CancellationTokenSource, DebugSessionOptions, TestRun, TestRunProfileKind, Uri } from 'vscode';
import { ChildProcess } from 'child_process';
import { IConfigurationService, ITestOutputChannel } from '../../../common/types';
import { Deferred, createDeferred } from '../../../common/utils/async';
Expand Down Expand Up @@ -166,15 +166,22 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {
runTestIdsPort: testIdsFileName,
pytestPort: resultNamedPipeName, // change this from pytest
};
const sessionOptions: DebugSessionOptions = {
testRun: runInstance,
};
traceInfo(`Running DEBUG unittest for workspace ${options.cwd} with arguments: ${args}\r\n`);

if (debugLauncher === undefined) {
traceError('Debug launcher is not defined');
throw new Error('Debug launcher is not defined');
}
await debugLauncher.launchDebugger(launchOptions, () => {
serverCancel.cancel();
});
await debugLauncher.launchDebugger(
launchOptions,
() => {
serverCancel.cancel();
},
sessionOptions,
);
} else {
// This means it is running the test
traceInfo(`Running unittests for workspace ${cwd} with arguments: ${args}\r\n`);
Expand Down

0 comments on commit 44df949

Please sign in to comment.