Skip to content

Commit 1bad58f

Browse files
committed
fix(langserver): stabilized resolving of variables in test case and keyword documentation
1 parent 1e7a562 commit 1bad58f

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

packages/language_server/src/robotcode/language_server/robotframework/parts/hover.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,19 @@ def _hover_default(self, nodes: List[ast.AST], document: TextDocument, position:
184184
)
185185

186186
if found_range is not None:
187-
txt = kw.to_markdown()
187+
188188
if kw.libtype == "RESOURCE":
189-
txt = namespace.imports_manager.replace_variables_scalar(
190-
txt,
191-
str(document.uri.to_path().parent),
192-
namespace.get_resolvable_variables(nodes, position),
189+
txt = kw.to_markdown(
190+
modify_doc_handler=lambda t: namespace.imports_manager.replace_variables_scalar(
191+
t,
192+
str(document.uri.to_path().parent),
193+
namespace.get_resolvable_variables(),
194+
ignore_errors=True,
195+
)
193196
)
197+
else:
198+
txt = kw.to_markdown()
199+
194200
result.append((found_range, txt))
195201
if result:
196202
r = result[0][0]
@@ -271,7 +277,8 @@ def hover_TestCase( # noqa: N802
271277
txt = namespace.imports_manager.replace_variables_scalar(
272278
txt,
273279
str(document.uri.to_path().parent),
274-
namespace.get_resolvable_variables(nodes, position),
280+
namespace.get_resolvable_variables(),
281+
ignore_errors=True,
275282
)
276283
return Hover(
277284
contents=MarkupContent(kind=MarkupKind.MARKDOWN, value=MarkDownFormatter().format(txt)),

packages/robot/src/robotcode/robot/diagnostics/imports_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,11 +1579,13 @@ def replace_variables_scalar(
15791579
scalar: str,
15801580
base_dir: str = ".",
15811581
variables: Optional[Dict[str, Any]] = None,
1582+
ignore_errors: bool = False,
15821583
) -> Any:
15831584
return replace_variables_scalar(
15841585
scalar,
15851586
str(self.root_folder),
15861587
base_dir,
15871588
self.get_resolvable_command_line_variables(),
15881589
variables,
1590+
ignore_errors=ignore_errors,
15891591
)

packages/robot/src/robotcode/robot/diagnostics/library_doc.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ def to_markdown(
711711
add_signature: bool = True,
712712
header_level: int = 2,
713713
add_type: bool = True,
714+
modify_doc_handler: Optional[Callable[[str], str]] = None,
714715
) -> str:
715716
result = ""
716717

@@ -723,12 +724,18 @@ def to_markdown(
723724

724725
result += f"##{'#' * header_level} Documentation:\n"
725726

727+
doc: Optional[str] = None
726728
if self.doc_format == ROBOT_DOC_FORMAT:
727-
result += MarkDownFormatter().format(self.doc)
729+
doc = MarkDownFormatter().format(self.doc)
728730
elif self.doc_format == REST_DOC_FORMAT:
729-
result += convert_from_rest(self.doc)
731+
doc = convert_from_rest(self.doc)
730732
else:
731-
result += self.doc
733+
doc = self.doc
734+
735+
if doc is not None:
736+
if modify_doc_handler is not None:
737+
doc = modify_doc_handler(doc)
738+
result += doc
732739

733740
return result
734741

@@ -1588,16 +1595,21 @@ def replace_variables_scalar(
15881595
base_dir: str = ".",
15891596
command_line_variables: Optional[Dict[str, Optional[Any]]] = None,
15901597
variables: Optional[Dict[str, Optional[Any]]] = None,
1598+
ignore_errors: bool = False,
15911599
) -> Any:
15921600

15931601
_update_env(working_dir)
15941602

15951603
if contains_variable(scalar, "$@&%"):
15961604
robot_variables = resolve_robot_variables(working_dir, base_dir, command_line_variables, variables)
15971605
if get_robot_version() >= (6, 1):
1598-
return VariableReplacer(robot_variables).replace_scalar(scalar.replace("\\", "\\\\"))
1606+
return VariableReplacer(robot_variables).replace_scalar(
1607+
scalar.replace("\\", "\\\\"), ignore_errors=ignore_errors
1608+
)
15991609

1600-
return VariableReplacer(robot_variables.store).replace_scalar(scalar.replace("\\", "\\\\"))
1610+
return VariableReplacer(robot_variables.store).replace_scalar(
1611+
scalar.replace("\\", "\\\\"), ignore_errors=ignore_errors
1612+
)
16011613

16021614
return scalar.replace("\\", "\\\\")
16031615

0 commit comments

Comments
 (0)