|
45 | 45 | from robot.parsing.lexer.tokens import Token as RobotToken
|
46 | 46 | from robot.parsing.model.blocks import Keyword
|
47 | 47 | from robot.parsing.model.statements import Arguments, KeywordName
|
48 |
| -from robot.running.arguments.argumentresolver import ( |
49 |
| - ArgumentResolver, |
50 |
| - DictToKwargs, |
51 |
| - NamedArgumentResolver, |
52 |
| - VariableReplacer, |
53 |
| -) |
| 48 | +from robot.running.arguments.argumentresolver import ArgumentResolver, DictToKwargs, NamedArgumentResolver |
| 49 | +from robot.running.arguments.argumentresolver import VariableReplacer as ArgumentsVariableReplacer |
54 | 50 | from robot.running.arguments.argumentspec import ArgInfo
|
55 | 51 | from robot.running.arguments.argumentspec import (
|
56 | 52 | ArgumentSpec as RobotArgumentSpec,
|
|
64 | 60 | from robot.variables import Variables
|
65 | 61 | from robot.variables.filesetter import PythonImporter, YamlImporter
|
66 | 62 | from robot.variables.finders import VariableFinder
|
| 63 | +from robot.variables.replacer import VariableReplacer |
67 | 64 | from robot.variables.search import contains_variable
|
68 | 65 | from robotcode.core.lsp.types import Position, Range
|
69 | 66 | from robotcode.core.utils.path import normalized_path
|
@@ -578,9 +575,9 @@ def _raise_positional_after_named(self) -> None:
|
578 | 575 |
|
579 | 576 | positional, named = MyNamedArgumentResolver(self.__robot_arguments).resolve(arguments, variables)
|
580 | 577 | if get_robot_version() < (7, 0):
|
581 |
| - positional, named = VariableReplacer(resolve_variables_until).replace(positional, named, variables) |
| 578 | + positional, named = ArgumentsVariableReplacer(resolve_variables_until).replace(positional, named, variables) |
582 | 579 | else:
|
583 |
| - positional, named = VariableReplacer(self.__robot_arguments, resolve_variables_until).replace( |
| 580 | + positional, named = ArgumentsVariableReplacer(self.__robot_arguments, resolve_variables_until).replace( |
584 | 581 | positional, named, variables
|
585 | 582 | )
|
586 | 583 | positional, named = DictToKwargs(self.__robot_arguments, dict_to_kwargs).handle(positional, named)
|
@@ -1585,6 +1582,26 @@ def resolve_variable(
|
1585 | 1582 | return name.replace("\\", "\\\\")
|
1586 | 1583 |
|
1587 | 1584 |
|
| 1585 | +def replace_variables_scalar( |
| 1586 | + scalar: str, |
| 1587 | + working_dir: str = ".", |
| 1588 | + base_dir: str = ".", |
| 1589 | + command_line_variables: Optional[Dict[str, Optional[Any]]] = None, |
| 1590 | + variables: Optional[Dict[str, Optional[Any]]] = None, |
| 1591 | +) -> Any: |
| 1592 | + |
| 1593 | + _update_env(working_dir) |
| 1594 | + |
| 1595 | + if contains_variable(scalar, "$@&%"): |
| 1596 | + robot_variables = resolve_robot_variables(working_dir, base_dir, command_line_variables, variables) |
| 1597 | + if get_robot_version() >= (6, 1): |
| 1598 | + return VariableReplacer(robot_variables).replace_scalar(scalar.replace("\\", "\\\\")) |
| 1599 | + |
| 1600 | + return VariableReplacer(robot_variables.store).replace_scalar(scalar.replace("\\", "\\\\")) |
| 1601 | + |
| 1602 | + return scalar.replace("\\", "\\\\") |
| 1603 | + |
| 1604 | + |
1588 | 1605 | @contextmanager
|
1589 | 1606 | def _std_capture() -> Iterator[io.StringIO]:
|
1590 | 1607 | old__stdout__ = sys.__stdout__
|
|
0 commit comments