Skip to content

Commit

Permalink
experimental: testMate.cmd.get-debug-args
Browse files Browse the repository at this point in the history
  • Loading branch information
matepek committed Mar 22, 2023
1 parent 2ac4bc9 commit e4971c2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## [4.3.11]

## [4.3.10] - 2022-12-26

### Fixed
Expand Down
19 changes: 15 additions & 4 deletions src/WorkspaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,26 @@ export class WorkspaceManager implements vscode.Disposable {
}
}

debug(test: AbstractTest, cancellation: vscode.CancellationToken, run: vscode.TestRun): Promise<void> {
debug(
test: AbstractTest,
cancellation: vscode.CancellationToken,
run: vscode.TestRun,
setDebugArgs: (args: string[]) => void,
): Promise<void> {
run.enqueued(test.item);

return this._debugInner(test, cancellation, run).catch(e => {
return this._debugInner(test, cancellation, run, setDebugArgs).catch(e => {
this.log.errorS('error during debug', e);
throw e;
});
}

async _debugInner(test: AbstractTest, cancellation: vscode.CancellationToken, run: vscode.TestRun): Promise<void> {
async _debugInner(
test: AbstractTest,
cancellation: vscode.CancellationToken,
run: vscode.TestRun,
setDebugArgs: (args: string[]) => void,
): Promise<void> {
try {
this._shared.log.info('Using debug');

Expand All @@ -401,6 +411,7 @@ export class WorkspaceManager implements vscode.Disposable {
const configuration = this._getConfiguration(this._shared.log);

const argsArray = executable.getDebugParams([test], configuration.getDebugBreakOnFailure());
setDebugArgs(argsArray);

const argsArrayFunc = async (): Promise<string[]> => argsArray;

Expand Down Expand Up @@ -451,7 +462,7 @@ export class WorkspaceManager implements vscode.Disposable {
{ resolve: '${argsArrayFlat}', rule: argsArrayFunc, isFlat: true },
{
resolve: '${argsStr}',
rule: (): string => '"' + argsArray.map(a => a.replace('"', '\\"')).join('" "') + '"',
rule: (): string => '"' + argsArray.map(a => a.replaceAll('"', '\\"')).join('" "') + '"',
},
{ resolve: '${cwd}', rule: executable.shared.options.cwd!.toString() },
{
Expand Down
18 changes: 15 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
SharedTestTags.runnable,
);

// https://github.com/matepek/vscode-catch2-test-adapter/issues/375
let currentDebugArgs: string[] = [];

const debugProfile = controller.createRunProfile(
'Debug Test',
vscode.TestRunProfileKind.Debug,
Expand Down Expand Up @@ -205,9 +208,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
}
const test = testsToRun.direct[0];
runQueue.push(
manager.debug(test, cancellation, testRun).catch(e => {
vscode.window.showErrorMessage('Unexpected error from debug: ' + e);
}),
manager
.debug(test, cancellation, testRun, (args: string[]) => (currentDebugArgs = args))
.catch(e => {
vscode.window.showErrorMessage('Unexpected error from debug: ' + e);
})
.finally(() => (currentDebugArgs = [])),
);
}

Expand Down Expand Up @@ -245,6 +251,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.commands.registerCommand('testMate.cmd.reload-workspaces', commandReloadWorkspaces),
);

context.subscriptions.push(
vscode.commands.registerCommand('testMate.cmd.get-debug-args', () =>
currentDebugArgs.map(a => a.replaceAll('"', '\\"')).join('" "'),
),
);

addOpenedWorkspaces();

log.info('Activation finished');
Expand Down

0 comments on commit e4971c2

Please sign in to comment.