Skip to content

Commit

Permalink
fix(langserver): stabilized resolving of variables in test case and k…
Browse files Browse the repository at this point in the history
…eyword documentation
  • Loading branch information
d-biehl committed Oct 9, 2024
1 parent 1e7a562 commit 1bad58f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,19 @@ def _hover_default(self, nodes: List[ast.AST], document: TextDocument, position:
)

if found_range is not None:
txt = kw.to_markdown()

if kw.libtype == "RESOURCE":
txt = namespace.imports_manager.replace_variables_scalar(
txt,
str(document.uri.to_path().parent),
namespace.get_resolvable_variables(nodes, position),
txt = kw.to_markdown(
modify_doc_handler=lambda t: namespace.imports_manager.replace_variables_scalar(
t,
str(document.uri.to_path().parent),
namespace.get_resolvable_variables(),
ignore_errors=True,
)
)
else:
txt = kw.to_markdown()

result.append((found_range, txt))
if result:
r = result[0][0]
Expand Down Expand Up @@ -271,7 +277,8 @@ def hover_TestCase( # noqa: N802
txt = namespace.imports_manager.replace_variables_scalar(
txt,
str(document.uri.to_path().parent),
namespace.get_resolvable_variables(nodes, position),
namespace.get_resolvable_variables(),
ignore_errors=True,
)
return Hover(
contents=MarkupContent(kind=MarkupKind.MARKDOWN, value=MarkDownFormatter().format(txt)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1579,11 +1579,13 @@ def replace_variables_scalar(
scalar: str,
base_dir: str = ".",
variables: Optional[Dict[str, Any]] = None,
ignore_errors: bool = False,
) -> Any:
return replace_variables_scalar(
scalar,
str(self.root_folder),
base_dir,
self.get_resolvable_command_line_variables(),
variables,
ignore_errors=ignore_errors,
)
22 changes: 17 additions & 5 deletions packages/robot/src/robotcode/robot/diagnostics/library_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ def to_markdown(
add_signature: bool = True,
header_level: int = 2,
add_type: bool = True,
modify_doc_handler: Optional[Callable[[str], str]] = None,
) -> str:
result = ""

Expand All @@ -723,12 +724,18 @@ def to_markdown(

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

doc: Optional[str] = None
if self.doc_format == ROBOT_DOC_FORMAT:
result += MarkDownFormatter().format(self.doc)
doc = MarkDownFormatter().format(self.doc)
elif self.doc_format == REST_DOC_FORMAT:
result += convert_from_rest(self.doc)
doc = convert_from_rest(self.doc)
else:
result += self.doc
doc = self.doc

if doc is not None:
if modify_doc_handler is not None:
doc = modify_doc_handler(doc)
result += doc

return result

Expand Down Expand Up @@ -1588,16 +1595,21 @@ def replace_variables_scalar(
base_dir: str = ".",
command_line_variables: Optional[Dict[str, Optional[Any]]] = None,
variables: Optional[Dict[str, Optional[Any]]] = None,
ignore_errors: bool = False,
) -> Any:

_update_env(working_dir)

if contains_variable(scalar, "$@&%"):
robot_variables = resolve_robot_variables(working_dir, base_dir, command_line_variables, variables)
if get_robot_version() >= (6, 1):
return VariableReplacer(robot_variables).replace_scalar(scalar.replace("\\", "\\\\"))
return VariableReplacer(robot_variables).replace_scalar(
scalar.replace("\\", "\\\\"), ignore_errors=ignore_errors
)

return VariableReplacer(robot_variables.store).replace_scalar(scalar.replace("\\", "\\\\"))
return VariableReplacer(robot_variables.store).replace_scalar(
scalar.replace("\\", "\\\\"), ignore_errors=ignore_errors
)

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

Expand Down

0 comments on commit 1bad58f

Please sign in to comment.