Skip to content

Commit

Permalink
Merge pull request #425 from matepek/advanced-debug-config
Browse files Browse the repository at this point in the history
debug config in advanced
  • Loading branch information
matepek authored Feb 21, 2024
2 parents 4b161ff + 2122e00 commit 78a8c98
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ node_modules

out

/test/cpp/build

*.vsix
.vscode-test

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Added

- `testMate.test.advancedExecutables` - `debug.configTemplate`

## [4.8.3] - 2024-02-07

### Added
Expand Down
1 change: 1 addition & 0 deletions documents/configuration/test.advancedExecutables.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ If it is an object it can contains the following properties:
| `strictPattern` | Test loading fails if one of the files matched by `pattern` is not a test executable. (Helps noticing unexpected crashes/problems under test loading.) |
| `markAsSkipped` | If true then all the tests related to the pattern are skipped. They can be run manually though. |
| `executableCloning` | If enabled it creates a copy of the test executable before listing or running the tests. NOTE: discovery (`--help`) still uses the original file. |
| `debug.configTemplate` | Sets the necessary debug configurations and the debug button will work. |
| `executableSuffixToInclude` | Filter files based on suffix for faster discovery. |
| `waitForBuildProcess` | Prevents the extension of auto-reloading. With this linking failure might can be avoided. Can be true to use a default pattern that works for most cases, or a string to pass your own search pattern (regex) for processes. |
| `catch2` | Object with framework specific settings. [Detail](https://github.com/matepek/vscode-catch2-test-adapter/blob/master/documents/configuration/test.advancedExecutables.md#framework-specific-settings) |
Expand Down
62 changes: 62 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,68 @@
"type": "boolean",
"default": false
},
"debug.configTemplate": {
"markdownDescription": "Sets the necessary debug configurations and the debug button will work.",
"scope": "resource",
"default": null,
"oneOf": [
{
"type": "string",
"pattern": "^(extensionOnly|name:.+)$"
},
{
"type": "object",
"properties": {
"type": {
"type": "string"
}
},
"required": [
"type"
],
"additionalProperties": {
"anyOf": [
{
"type": "string",
"enum": [
"${exec}",
"${argsArray}",
"${argsArrayFlat}",
"${argsStr}",
"${cwd}",
"${envObj}",
"${envObjArray}",
"${sourceFileMapObj}",
"${label}",
"${parentLabel}"
]
},
{
"type": "string"
},
{
"type": "array"
},
{
"type": "boolean"
},
{
"type": "null"
},
{
"type": "number"
},
{
"type": "object"
}
]
}
},
{
"type": "null"
}
]
},
"executableSuffixToInclude": {
"markdownDescription": "Filter files based on suffix for faster discovery.",
"type": "array",
Expand Down
2 changes: 2 additions & 0 deletions src/AdvancedExecutableInterface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DebugConfig } from './DebugConfigType';
import { TestGroupingConfig } from './TestGroupingInterface';

///
Expand All @@ -20,6 +21,7 @@ export type AdvancedExecutableConfig = {
executableCloning?: boolean;
executableSuffixToInclude?: string[];
waitForBuildProcess?: boolean | string;
'debug.configTemplate': DebugConfig;
catch2?: FrameworkSpecificConfig;
gtest?: FrameworkSpecificConfig;
doctest?: FrameworkSpecificConfig;
Expand Down
3 changes: 3 additions & 0 deletions src/ConfigOfExecGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { readFileSync } from 'fs';
import { getModiTime } from './Util';
import { SubProgressReporter } from './util/ProgressReporter';
import { ExecCloner } from './framework/AbstractExecutable';
import { DebugConfigData } from './DebugConfigType';

///

Expand All @@ -43,6 +44,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {
private readonly _executableCloning: boolean | undefined,
executableSuffixToInclude: string[] | undefined,
private readonly _waitForBuildProcess: boolean | string | undefined,
private readonly _debugConfigData: DebugConfigData | undefined,
private readonly _executionWrapper: ExecutionWrapperConfig | undefined,
private readonly _sourceFileMap: Record<string, string>,
private readonly _frameworkSpecific: Record<FrameworkType, FrameworkSpecificConfig>,
Expand Down Expand Up @@ -417,6 +419,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {
this._parallelizationLimit,
this._markAsSkipped === true,
this._executableCloning === true,
this._debugConfigData,
this._executableSuffixToInclude,
this._executableSuffixToExclude,
this._runTask,
Expand Down
36 changes: 16 additions & 20 deletions src/Configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from './AdvancedExecutableInterface';
import { platformUtil } from './util/Platform';
import { cloneRecursively } from './util/ResolveRule';
import { DebugConfigData } from './DebugConfigType';

type SentryValue = 'question' | 'enable' | 'enabled' | 'disable' | 'disable_1' | 'disable_2' | 'disable_3';

Expand Down Expand Up @@ -118,13 +119,10 @@ export class Configurations {
return vscode.extensions.all.find(e => e.id === id) !== undefined;
}

getDebugConfigurationTemplate(): DebugConfigData {
private _getDebugConfigData(
templateFromConfig: vscode.DebugConfiguration | null | 'extensionOnly' | string,
): DebugConfigData {
const debugConfigData = ((): DebugConfigData => {
const templateFromConfig = this._getD<vscode.DebugConfiguration | null | 'extensionOnly' | string>(
'debug.configTemplate',
null,
);

const template: vscode.DebugConfiguration = {
name: '${label} (${parentLabel})',
request: 'launch',
Expand Down Expand Up @@ -286,6 +284,12 @@ export class Configurations {
return debugConfigData;
}

getDebugConfigurationTemplate(): DebugConfigData {
return this._getDebugConfigData(
this._getD<vscode.DebugConfiguration | null | 'extensionOnly' | string>('debug.configTemplate', null),
);
}

getOrCreateUserId(): string {
let userId = this._get<string>('log.userId');

Expand Down Expand Up @@ -465,6 +469,7 @@ export class Configurations {
undefined,
undefined,
undefined,
undefined,
{},
{
catch2: {},
Expand Down Expand Up @@ -574,6 +579,10 @@ export class Configurations {

const waitForBuildProcess: boolean | string | undefined = obj.waitForBuildProcess;

const debugConfigData: DebugConfigData | undefined = obj['debug.configTemplate']
? this._getDebugConfigData(obj['debug.configTemplate'])
: undefined;

const defaultTestGrouping = obj.testGrouping;

const spawnerConfig: ExecutionWrapperConfig | undefined =
Expand Down Expand Up @@ -606,6 +615,7 @@ export class Configurations {
executableCloning,
executableSuffixToInclude,
waitForBuildProcess,
debugConfigData,
spawnerConfig,
sourceFileMap,
{
Expand Down Expand Up @@ -675,17 +685,3 @@ export class Configurations {
return {};
}
}

export type DebugConfigTemplateSource =
| 'fromLaunchJson'
| 'fromLaunchJsonByName'
| 'userDefined'
| 'vadimcn.vscode-lldb'
| 'ms-vscode.cpptools'
| 'webfreak.debug';

export type DebugConfigData = {
template: vscode.DebugConfiguration;
source: DebugConfigTemplateSource;
launchSourceFileMap?: Record<string, string>;
};
17 changes: 17 additions & 0 deletions src/DebugConfigType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as vscode from 'vscode';

export type DebugConfig = vscode.DebugConfiguration | null | 'extensionOnly' | string;

export type DebugConfigTemplateSource =
| 'fromLaunchJson'
| 'fromLaunchJsonByName'
| 'userDefined'
| 'vadimcn.vscode-lldb'
| 'ms-vscode.cpptools'
| 'webfreak.debug';

export type DebugConfigData = {
template: vscode.DebugConfiguration;
source: DebugConfigTemplateSource;
launchSourceFileMap?: Record<string, string>;
};
2 changes: 1 addition & 1 deletion src/WorkspaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class WorkspaceManager implements vscode.Disposable {

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

const debugConfigData = configuration.getDebugConfigurationTemplate();
const debugConfigData = executable.shared.debugConfigData ?? configuration.getDebugConfigurationTemplate();

this._shared.log.info('debug config data', {
source: debugConfigData.source,
Expand Down
3 changes: 3 additions & 0 deletions src/framework/ExecutableFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { GoogleBenchmarkExecutable } from './GoogleBenchmark/GoogleBenchmarkExec
import { ResolveRuleAsync } from '../util/ResolveRule';
import { WorkspaceShared } from '../WorkspaceShared';
import { Framework, FrameworkId, FrameworkType } from './Framework';
import { DebugConfigData } from '../DebugConfigType';

export class ExecutableFactory {
constructor(
Expand All @@ -23,6 +24,7 @@ export class ExecutableFactory {
private readonly _parallelizationLimit: number,
private readonly _markAsSkipped: boolean,
private readonly _executableCloning: boolean,
private readonly _debugConfigData: DebugConfigData | undefined,
private readonly _executableSuffixToInclude: Set<string> | undefined,
private readonly _executableSuffixToExclude: Set<string> | undefined,
private readonly _runTask: RunTaskConfig,
Expand Down Expand Up @@ -74,6 +76,7 @@ export class ExecutableFactory {
this._parallelizationLimit,
this._markAsSkipped,
this._executableCloning,
this._debugConfigData,
this._runTask,
this._spawner,
this._resolvedSourceFileMap,
Expand Down
2 changes: 2 additions & 0 deletions src/framework/SharedVarOfExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ResolveRuleAsync } from '../util/ResolveRule';
import { TaskPool } from '../util/TaskPool';
import { Spawner, SpawnOptionsWithoutStdio } from '../Spawner';
import { WorkspaceShared } from '../WorkspaceShared';
import { DebugConfigData } from '../DebugConfigType';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const hash = require('object-hash');
Expand All @@ -20,6 +21,7 @@ export class SharedVarOfExec {
_parallelizationLimit: number,
readonly markAsSkipped: boolean,
readonly executableCloning: boolean,
readonly debugConfigData: DebugConfigData | undefined,
readonly runTask: RunTaskConfig,
readonly spawner: Spawner,
readonly resolvedSourceFileMap: Record<string, string>,
Expand Down
11 changes: 11 additions & 0 deletions test/cpp/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"cmake.configureOnOpen": true,
"testMate.cpp.test.advancedExecutables": [
{
"pattern":"build/**/*{test,Test,TEST}*",
"runTask": {
"before": ["build_all"]
}
}
]
}
25 changes: 25 additions & 0 deletions test/cpp/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello ${command:cmake.buildDirectory}",
"problemMatcher": []
},
{
"type": "cmake",
"label": "build_all",
"command": "build",
"targets": [
"all"
],
"preset": "${command:cmake.activeBuildPresetName}",
"group": "build",
"problemMatcher": [],
"detail": "CMake template build task"
}
]
}

0 comments on commit 78a8c98

Please sign in to comment.