From 2122e008711a30e03124b16292ce69f5e3b7ad63 Mon Sep 17 00:00:00 2001 From: Mate Pek Date: Fri, 16 Feb 2024 22:30:24 +0700 Subject: [PATCH] debug confing in advanced --- .gitignore | 2 + CHANGELOG.md | 4 ++ .../configuration/test.advancedExecutables.md | 1 + package.json | 62 +++++++++++++++++++ src/AdvancedExecutableInterface.ts | 2 + src/ConfigOfExecGroup.ts | 3 + src/Configurations.ts | 36 +++++------ src/DebugConfigType.ts | 17 +++++ src/WorkspaceManager.ts | 2 +- src/framework/ExecutableFactory.ts | 3 + src/framework/SharedVarOfExec.ts | 2 + test/cpp/.vscode/settings.json | 11 ++++ test/cpp/.vscode/tasks.json | 25 ++++++++ 13 files changed, 149 insertions(+), 21 deletions(-) create mode 100644 src/DebugConfigType.ts create mode 100644 test/cpp/.vscode/settings.json create mode 100644 test/cpp/.vscode/tasks.json diff --git a/.gitignore b/.gitignore index 524b6e01..4c9f0c7a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ node_modules out +/test/cpp/build + *.vsix .vscode-test diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e98e7f6..bee8deca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/documents/configuration/test.advancedExecutables.md b/documents/configuration/test.advancedExecutables.md index 3c08bf5d..82f29ed3 100644 --- a/documents/configuration/test.advancedExecutables.md +++ b/documents/configuration/test.advancedExecutables.md @@ -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) | diff --git a/package.json b/package.json index ac8c5c6f..d75d19a1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/AdvancedExecutableInterface.ts b/src/AdvancedExecutableInterface.ts index 778d82d5..c54f1060 100644 --- a/src/AdvancedExecutableInterface.ts +++ b/src/AdvancedExecutableInterface.ts @@ -1,3 +1,4 @@ +import { DebugConfig } from './DebugConfigType'; import { TestGroupingConfig } from './TestGroupingInterface'; /// @@ -20,6 +21,7 @@ export type AdvancedExecutableConfig = { executableCloning?: boolean; executableSuffixToInclude?: string[]; waitForBuildProcess?: boolean | string; + 'debug.configTemplate': DebugConfig; catch2?: FrameworkSpecificConfig; gtest?: FrameworkSpecificConfig; doctest?: FrameworkSpecificConfig; diff --git a/src/ConfigOfExecGroup.ts b/src/ConfigOfExecGroup.ts index 327d66c4..169d11a5 100644 --- a/src/ConfigOfExecGroup.ts +++ b/src/ConfigOfExecGroup.ts @@ -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'; /// @@ -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, private readonly _frameworkSpecific: Record, @@ -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, diff --git a/src/Configurations.ts b/src/Configurations.ts index 070b82ef..0d70496e 100644 --- a/src/Configurations.ts +++ b/src/Configurations.ts @@ -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'; @@ -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( - 'debug.configTemplate', - null, - ); - const template: vscode.DebugConfiguration = { name: '${label} (${parentLabel})', request: 'launch', @@ -286,6 +284,12 @@ export class Configurations { return debugConfigData; } + getDebugConfigurationTemplate(): DebugConfigData { + return this._getDebugConfigData( + this._getD('debug.configTemplate', null), + ); + } + getOrCreateUserId(): string { let userId = this._get('log.userId'); @@ -465,6 +469,7 @@ export class Configurations { undefined, undefined, undefined, + undefined, {}, { catch2: {}, @@ -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 = @@ -606,6 +615,7 @@ export class Configurations { executableCloning, executableSuffixToInclude, waitForBuildProcess, + debugConfigData, spawnerConfig, sourceFileMap, { @@ -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; -}; diff --git a/src/DebugConfigType.ts b/src/DebugConfigType.ts new file mode 100644 index 00000000..3e09714c --- /dev/null +++ b/src/DebugConfigType.ts @@ -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; +}; diff --git a/src/WorkspaceManager.ts b/src/WorkspaceManager.ts index 354ff08c..b483773c 100644 --- a/src/WorkspaceManager.ts +++ b/src/WorkspaceManager.ts @@ -405,7 +405,7 @@ export class WorkspaceManager implements vscode.Disposable { const argsArrayFunc = async (): Promise => argsArray; - const debugConfigData = configuration.getDebugConfigurationTemplate(); + const debugConfigData = executable.shared.debugConfigData ?? configuration.getDebugConfigurationTemplate(); this._shared.log.info('debug config data', { source: debugConfigData.source, diff --git a/src/framework/ExecutableFactory.ts b/src/framework/ExecutableFactory.ts index cbe64d47..171c9d9f 100644 --- a/src/framework/ExecutableFactory.ts +++ b/src/framework/ExecutableFactory.ts @@ -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( @@ -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 | undefined, private readonly _executableSuffixToExclude: Set | undefined, private readonly _runTask: RunTaskConfig, @@ -74,6 +76,7 @@ export class ExecutableFactory { this._parallelizationLimit, this._markAsSkipped, this._executableCloning, + this._debugConfigData, this._runTask, this._spawner, this._resolvedSourceFileMap, diff --git a/src/framework/SharedVarOfExec.ts b/src/framework/SharedVarOfExec.ts index 6a196067..c792e198 100644 --- a/src/framework/SharedVarOfExec.ts +++ b/src/framework/SharedVarOfExec.ts @@ -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'); @@ -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, diff --git a/test/cpp/.vscode/settings.json b/test/cpp/.vscode/settings.json new file mode 100644 index 00000000..714f744f --- /dev/null +++ b/test/cpp/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "cmake.configureOnOpen": true, + "testMate.cpp.test.advancedExecutables": [ + { + "pattern":"build/**/*{test,Test,TEST}*", + "runTask": { + "before": ["build_all"] + } + } + ] +} \ No newline at end of file diff --git a/test/cpp/.vscode/tasks.json b/test/cpp/.vscode/tasks.json new file mode 100644 index 00000000..198891a4 --- /dev/null +++ b/test/cpp/.vscode/tasks.json @@ -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" + } + ] +} \ No newline at end of file