Skip to content

Commit 427ac58

Browse files
committed
Rework handling of launching and debugging tests fixes #54
1 parent 683b683 commit 427ac58

File tree

3 files changed

+143
-41
lines changed

3 files changed

+143
-41
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to the "robotcode" extension will be documented in this file
55
## [Unreleased]
66

77
- Support for Robocop >= 2.4
8+
- Rework handling of launching and debugging tests
9+
- fixes [#54](https://github.com/d-biehl/robotcode/issues/54)
10+
- a launch configuration can now have a `purpose`:
11+
- `test`: Use this configuration when running or debugging tests.
12+
- `default`: Use this configuration as default for all other configurations.
813

914
## 0.13.7
1015

package.json

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"capabilities": {
5252
"untrustedWorkspaces": {
5353
"supported": "limited",
54-
"description": "Only Partial IntelliSense with RobotCode is supported. Cannot execute Python with untrusted files."
54+
"description": "Only Partial IntelliSense is supported."
5555
},
5656
"virtualWorkspaces": {
5757
"supported": "limited",
@@ -611,6 +611,9 @@
611611
"default": "${workspaceFolder}"
612612
},
613613
"env": {
614+
"additionalProperties": {
615+
"type": "string"
616+
},
614617
"type": "object",
615618
"description": "Environment variables defined as a key value pair.",
616619
"default": []
@@ -654,7 +657,10 @@
654657
"default": false
655658
},
656659
"pythonConfiguration": {
657-
"type": "object",
660+
"type": [
661+
"object",
662+
"string"
663+
],
658664
"description": "Defines a template for the python launch configuration.",
659665
"default": {}
660666
},
@@ -723,6 +729,32 @@
723729
],
724730
"description": "Specifies robot execution mode.",
725731
"default": "default"
732+
},
733+
"purpose": {
734+
"type": [
735+
"array",
736+
"string"
737+
],
738+
"enum": [
739+
"default",
740+
"test"
741+
],
742+
"enumDescriptions": [
743+
"Use this configuration as default for all other configurations.",
744+
"Use this configuration when running or debugging tests."
745+
],
746+
"default": [],
747+
"description": "Defines what purpose this configuration has.",
748+
"items": {
749+
"enum": [
750+
"default",
751+
"test"
752+
],
753+
"enumDescriptions": [
754+
"Use this configuration as default for all other configurations.",
755+
"Use this configuration when running or debugging tests."
756+
]
757+
}
726758
}
727759
}
728760
}
@@ -741,6 +773,25 @@
741773
"request": "launch",
742774
"cwd": "${workspaceFolder}",
743775
"target": "."
776+
},
777+
{
778+
"name": "RobotCode: Default",
779+
"type": "robotcode",
780+
"request": "launch",
781+
"purpose": "default",
782+
"presentation": {
783+
"hidden": true
784+
},
785+
"pythonConfiguration": "RobotCode: Debug"
786+
},
787+
{
788+
"name": "RobotCode: Python",
789+
"type": "python",
790+
"request": "attach",
791+
"presentation": {
792+
"hidden": true
793+
},
794+
"justMyCode": false
744795
}
745796
],
746797
"configurationSnippets": [
@@ -765,6 +816,32 @@
765816
"cwd": "^\"\\${workspaceFolder}\"",
766817
"target": "."
767818
}
819+
},
820+
{
821+
"label": "RobotCode: Test",
822+
"description": "Run or debug tests from test explorer.",
823+
"body": {
824+
"name": "RobotCode: Test",
825+
"type": "robotcode",
826+
"request": "launch",
827+
"presentation": {
828+
"hidden": true
829+
},
830+
"purpose": "test"
831+
}
832+
},
833+
{
834+
"label": "RobotCode: Default",
835+
"description": "Default configuration.",
836+
"body": {
837+
"name": "RobotCode: Default",
838+
"type": "robotcode",
839+
"request": "launch",
840+
"presentation": {
841+
"hidden": true
842+
},
843+
"purpose": "default"
844+
}
768845
}
769846
]
770847
}

vscode-client/debugmanager.ts

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class RobotCodeDebugConfigurationProvider implements vscode.DebugConfigurationPr
4949

5050
// eslint-disable-next-line class-methods-use-this
5151
async _resolveDebugConfiguration(
52-
_folder: vscode.WorkspaceFolder | undefined,
52+
folder: vscode.WorkspaceFolder | undefined,
5353
debugConfiguration: vscode.DebugConfiguration,
5454
token?: vscode.CancellationToken
5555
): Promise<vscode.DebugConfiguration> {
@@ -71,23 +71,23 @@ class RobotCodeDebugConfigurationProvider implements vscode.DebugConfigurationPr
7171
}
7272
}
7373

74-
return debugConfiguration;
75-
}
74+
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
7675

77-
resolveDebugConfigurationWithSubstitutedVariables(
78-
folder: vscode.WorkspaceFolder | undefined,
79-
debugConfiguration: vscode.DebugConfiguration,
80-
_token?: vscode.CancellationToken
81-
): vscode.ProviderResult<vscode.DebugConfiguration> {
82-
return this._resolveDebugConfigurationWithSubstitutedVariablesAsync(folder, debugConfiguration, _token);
83-
}
76+
const template = config.get("debug.defaultConfiguration", {});
8477

85-
async _resolveDebugConfigurationWithSubstitutedVariablesAsync(
86-
folder: vscode.WorkspaceFolder | undefined,
87-
debugConfiguration: vscode.DebugConfiguration,
88-
_token?: vscode.CancellationToken
89-
): Promise<vscode.DebugConfiguration> {
90-
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
78+
const defaultLaunchConfig =
79+
vscode.workspace
80+
.getConfiguration("launch", folder)
81+
?.get<{ [Key: string]: unknown }[]>("configurations")
82+
?.find(
83+
(v) =>
84+
v?.type === "robotcode" &&
85+
(v?.purpose === "default" || (Array.isArray(v?.purpose) && v?.purpose?.indexOf("default") > -1))
86+
) ?? {};
87+
88+
console.log(defaultLaunchConfig);
89+
90+
debugConfiguration = { ...template, ...defaultLaunchConfig, ...debugConfiguration };
9191

9292
try {
9393
if (path.isAbsolute(debugConfiguration.target)) {
@@ -101,23 +101,27 @@ class RobotCodeDebugConfigurationProvider implements vscode.DebugConfigurationPr
101101

102102
debugConfiguration.robotPythonPath = [
103103
...config.get<string[]>("robot.pythonPath", []),
104+
...(Array.isArray(defaultLaunchConfig?.robotPythonPath) ? defaultLaunchConfig.robotPythonPath : []),
104105
...(debugConfiguration.robotPythonPath ?? []),
105106
];
106107

107108
debugConfiguration.args = [...config.get<string[]>("robot.args", []), ...(debugConfiguration.args ?? [])];
108109

109110
debugConfiguration.variableFiles = [
110111
...config.get<string[]>("robot.variableFiles", []),
112+
...(Array.isArray(defaultLaunchConfig?.variableFiles) ? defaultLaunchConfig.variableFiles : []),
111113
...(debugConfiguration.variableFiles ?? []),
112114
];
113115

114116
debugConfiguration.variables = {
115117
...config.get<{ [Key: string]: unknown }>("robot.variables", {}),
118+
...(Array.isArray(defaultLaunchConfig?.variables) ? defaultLaunchConfig.variables : []),
116119
...(debugConfiguration.variables ?? {}),
117120
};
118121

119122
debugConfiguration.env = {
120123
...config.get<{ [Key: string]: unknown }>("robot.env", {}),
124+
...(defaultLaunchConfig?.env ?? {}),
121125
...(debugConfiguration.env ?? {}),
122126
};
123127

@@ -157,9 +161,7 @@ class RobotCodeDebugConfigurationProvider implements vscode.DebugConfigurationPr
157161
}
158162
}
159163

160-
const template = config.get("debug.defaultConfiguration", {});
161-
162-
return { ...template, ...debugConfiguration };
164+
return debugConfiguration;
163165
}
164166
}
165167

@@ -344,13 +346,23 @@ export class DebugManager {
344346

345347
args.push(`robotcode.debugger.modifiers.ExcludedByLongName${separator}${excluded.join(separator)}`);
346348
}
347-
const template = config.get("debug.defaultConfiguration", {});
349+
350+
const testLaunchConfig =
351+
vscode.workspace
352+
.getConfiguration("launch", folder)
353+
?.get<{ [Key: string]: unknown }[]>("configurations")
354+
?.find(
355+
(v) =>
356+
v?.type === "robotcode" &&
357+
(v?.purpose === "test" || (Array.isArray(v?.purpose) && v?.purpose?.indexOf("test") > -1))
358+
) ?? {};
359+
348360
const paths = config.get("robot.paths", []);
349361

350362
await vscode.debug.startDebugging(
351363
folder,
352364
{
353-
...template,
365+
...testLaunchConfig,
354366
...{
355367
type: "robotcode",
356368
name: "RobotCode: Run Tests",
@@ -379,26 +391,34 @@ export class DebugManager {
379391
options &&
380392
options.port
381393
) {
382-
await vscode.debug.startDebugging(
383-
session.workspaceFolder,
384-
{
385-
...session.configuration.pythonConfiguration,
386-
...{
387-
type: "python",
388-
name: `Python ${session.name}`,
389-
request: "attach",
390-
connect: {
391-
port: options.port,
392-
},
394+
let pythonConfiguration = session.configuration.pythonConfiguration ?? {};
395+
396+
if (typeof pythonConfiguration === "string" || pythonConfiguration instanceof String) {
397+
pythonConfiguration =
398+
vscode.workspace
399+
.getConfiguration("launch", session.workspaceFolder)
400+
?.get<{ [Key: string]: unknown }[]>("configurations")
401+
?.find((v) => v?.type === "python" && v?.name === pythonConfiguration) ?? {};
402+
}
403+
404+
const debugConfiguration = {
405+
...pythonConfiguration,
406+
...{
407+
type: "python",
408+
name: `Python ${session.name}`,
409+
request: "attach",
410+
connect: {
411+
port: options.port,
393412
},
394413
},
395-
{
396-
parentSession: session,
397-
compact: true,
398-
lifecycleManagedByParent: false,
399-
consoleMode: vscode.DebugConsoleMode.MergeWithParent,
400-
}
401-
);
414+
};
415+
416+
await vscode.debug.startDebugging(session.workspaceFolder, debugConfiguration, {
417+
parentSession: session,
418+
compact: true,
419+
lifecycleManagedByParent: false,
420+
consoleMode: vscode.DebugConsoleMode.MergeWithParent,
421+
});
402422
}
403423
}
404424

0 commit comments

Comments
 (0)