Skip to content

Commit 5c3a5d8

Browse files
committed
implement handling of robot running mode (rpa/nonrpa) fixes #21
1 parent 47fa4d2 commit 5c3a5d8

File tree

6 files changed

+78
-8
lines changed

6 files changed

+78
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ All notable changes to the "robotcode" extension will be documented in this file
88

99
- Optimize collecting model errors
1010
- also fixes [#42](https://github.com/d-biehl/robotcode/issues/42)
11+
- Add `mode` property to launch configuration and `robotcode.robot.mode` setting for global/workspace/folder
12+
- define the robot running mode (default, rpa, norpa)
13+
- corresponds to the '--rpa', '--norpa' option of the robot module.
14+
- fixes [#21](https://github.com/d-biehl/robotcode/issues/21)
1115

1216
## 0.8.0
1317

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,22 @@
315315
"description": "Specifies the output directory where robotframework saves output files.",
316316
"scope": "resource"
317317
},
318+
"robotcode.robot.mode": {
319+
"type": "string",
320+
"enum": [
321+
"default",
322+
"rpa",
323+
"norpa"
324+
],
325+
"enumDescriptions": [
326+
"Mode is got from test/task header in data files.",
327+
"Turn on the generic automation mode. Corresponds to the '--rpa' option of the robot module.",
328+
"Force test automation mode. Corresponds to the '--norpa' option of the robot module."
329+
],
330+
"description": "Specifies robot execution mode.",
331+
"default": "default",
332+
"scope": "resource"
333+
},
318334
"robotcode.debug.defaultConfiguration": {
319335
"type": "object",
320336
"default": {},
@@ -587,6 +603,21 @@
587603
"type": "boolean",
588604
"description": "Group start and stop suite/test/keyword messages in debug console.",
589605
"default": false
606+
},
607+
"mode": {
608+
"type": "string",
609+
"enum": [
610+
"default",
611+
"rpa",
612+
"norpa"
613+
],
614+
"enumDescriptions": [
615+
"Mode is got from test/task header in data files.",
616+
"Turn on the generic automation mode. Corresponds to the '--rpa' option of the robot module.",
617+
"Force test automation mode. Corresponds to the '--norpa' option of the robot module."
618+
],
619+
"description": "Specifies robot execution mode.",
620+
"default": "default"
590621
}
591622
}
592623
}

robotcode/debugger/launcher/server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ async def _launch(
142142
stopOnEntry: Optional[bool] = False, # noqa: N803
143143
arguments: Optional[LaunchRequestArguments] = None,
144144
dryRun: Optional[bool] = None,
145+
mode: Optional[str] = None,
145146
*_args: Any,
146147
**_kwargs: Any,
147148
) -> None:
@@ -180,6 +181,12 @@ async def _launch(
180181

181182
run_args += ["--"]
182183

184+
if mode:
185+
if mode == "rpa":
186+
run_args += ["--rpa"]
187+
elif mode == "norpa":
188+
run_args += ["--norpa"]
189+
183190
if dryRun:
184191
run_args += ["--dryrun"]
185192

robotcode/language_server/robotframework/configuration.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ class RobotConfig(ConfigBase):
2424
log_file: Optional[str] = None
2525
debug_file: Optional[str] = None
2626
log_level: Optional[str] = None
27+
mode: Optional[str] = None
28+
29+
def get_mode(self) -> Optional[bool]:
30+
if self.mode == "rpa":
31+
return True
32+
elif self.mode == "norpa":
33+
return False
34+
return None
2735

2836

2937
@config_section("robotcode.syntax")

robotcode/language_server/robotframework/parts/discovering.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Range,
1919
TextDocumentIdentifier,
2020
)
21+
from ..configuration import RobotConfig
2122
from ..utils.async_ast import AsyncVisitor
2223
from .protocol_part import RobotLanguageServerProtocolPart
2324

@@ -103,8 +104,15 @@ class DiscoveringProtocolPart(RobotLanguageServerProtocolPart):
103104
def __init__(self, parent: RobotLanguageServerProtocol) -> None:
104105
super().__init__(parent)
105106

107+
async def get_config(self, workspace_uri: str) -> Optional[RobotConfig]:
108+
folder = self.parent.workspace.get_workspace_folder(workspace_uri)
109+
if folder is None:
110+
return None
111+
112+
return await self.parent.workspace.get_configuration(RobotConfig, folder.uri)
113+
106114
async def _get_tests_from_workspace(
107-
self, workspace_folder: Path, paths: Optional[List[str]], suites: Optional[List[str]]
115+
self, workspace_folder: str, paths: Optional[List[str]], suites: Optional[List[str]]
108116
) -> List[TestItem]:
109117

110118
from robot.output.logger import LOGGER
@@ -188,6 +196,9 @@ def _get_parsers(self, extensions: List[str], process_curdir: bool) -> RobotPars
188196
parsers[ext] = robot_parser
189197
return parsers
190198

199+
def _validate_execution_mode(self, suite: Any) -> None:
200+
super()._validate_execution_mode(suite)
201+
191202
class MyTestSuiteBuilder(TestSuiteBuilder):
192203
def _validate_test_counts(self, suite: TestSuite, multisource: bool = False) -> None:
193204
# we don't need this
@@ -240,8 +251,12 @@ def generate(suite: TestSuite) -> TestItem:
240251
else None,
241252
)
242253

254+
workspace_path = Uri(workspace_folder).to_path()
243255
with LOGGER.cache_only:
244256
try:
257+
config = await self.get_config(workspace_folder)
258+
mode = config.get_mode() if config is not None else None
259+
245260
if paths and len(paths):
246261

247262
def normalize_paths(paths: List[str]) -> Iterator[str]:
@@ -251,7 +266,7 @@ def normalize_paths(paths: List[str]) -> Iterator[str]:
251266
p = Path(path)
252267

253268
if not p.is_absolute():
254-
p = Path(workspace_folder, p)
269+
p = Path(workspace_path, p)
255270

256271
if p.exists():
257272
yield str(p)
@@ -263,14 +278,17 @@ def nonexisting_paths(paths: List[str]) -> Iterator[str]:
263278
p = Path(path)
264279

265280
if not p.is_absolute():
266-
p = Path(workspace_folder, p)
281+
p = Path(workspace_path, p)
267282

268283
if not p.exists():
269284
yield str(p)
270285

271286
valid_paths = [i for i in normalize_paths(paths)]
272287
suite: Optional[TestSuite] = (
273-
MyTestSuiteBuilder(included_suites=suites if suites else None).build(*valid_paths)
288+
MyTestSuiteBuilder(
289+
included_suites=suites if suites else None,
290+
rpa=mode,
291+
).build(*valid_paths)
274292
if valid_paths
275293
else None
276294
)
@@ -301,7 +319,9 @@ def nonexisting_paths(paths: List[str]) -> Iterator[str]:
301319
else:
302320
return [
303321
generate(
304-
MyTestSuiteBuilder(included_suites=suites if suites else None).build(str(workspace_folder))
322+
MyTestSuiteBuilder(included_suites=suites if suites else None, rpa=mode).build(
323+
str(workspace_path)
324+
)
305325
)
306326
]
307327
except (SystemExit, KeyboardInterrupt):
@@ -327,9 +347,7 @@ async def get_tests_from_workspace(
327347
*args: Any,
328348
**kwargs: Any,
329349
) -> List[TestItem]:
330-
return await run_coroutine_in_thread(
331-
self._get_tests_from_workspace, Uri(workspace_folder).to_path(), paths, suites
332-
)
350+
return await run_coroutine_in_thread(self._get_tests_from_workspace, workspace_folder, paths, suites)
333351

334352
@rpc_method(name="robot/discovering/getTestsFromDocument", param_type=GetTestsParams)
335353
@_logger.call

vscode-client/debugmanager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class RobotCodeDebugConfigurationProvider implements vscode.DebugConfigurationPr
119119
debugConfiguration.outputDir =
120120
debugConfiguration?.outputDir ?? config.get<string | undefined>("robot.outputDir", undefined);
121121

122+
debugConfiguration.mode = debugConfiguration?.mode ?? config.get<string | undefined>("robot.mode", undefined);
123+
122124
debugConfiguration.attachPython = debugConfiguration?.attachPython ?? config.get<boolean>("debug.attachPython");
123125

124126
debugConfiguration.outputMessages =

0 commit comments

Comments
 (0)