From 2c8ed5662be1e8621d7d9c742275ccaf1809d06c Mon Sep 17 00:00:00 2001 From: Daniel Biehl Date: Tue, 26 Nov 2024 17:22:34 +0100 Subject: [PATCH] fix(analyzer): correct handling of variables in embedded args in keyword calls closes #360 --- .../robotframework/parts/semantic_tokens.py | 10 ++++++---- .../robotcode/robot/diagnostics/namespace_analyzer.py | 7 +++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py index cf7f9c56..517ede74 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py @@ -404,7 +404,7 @@ def generate_sem_sub_tokens( ): if ( namespace.find_keyword( - token.value, + unescape(token.value), # TODO: this must be resovle possible variables raise_keyword_error=False, handle_bdd_style=False, ) @@ -458,7 +458,9 @@ def generate_sem_sub_tokens( kw_namespace: Optional[str] = None kw: str = token.value - kw_doc = namespace.find_keyword(token.value, raise_keyword_error=False) + kw_doc = namespace.find_keyword( + unescape(token.value), raise_keyword_error=False + ) # TODO: this must be resovle possible variables ( lib_entry, @@ -1121,14 +1123,14 @@ def get_tokens() -> Iterator[Tuple[Token, ast.AST]]: kw: Optional[str] = None for _, n in iter_over_keyword_names_and_owners( - ModelHelper.strip_bdd_prefix(namespace, kw_token).value + unescape(ModelHelper.strip_bdd_prefix(namespace, kw_token).value) ): if n is not None: matcher = KeywordMatcher(n) if matcher in ALL_RUN_KEYWORDS_MATCHERS: kw = n if kw: - kw_doc = namespace.find_keyword(kw_token.value) + kw_doc = namespace.find_keyword(unescape(kw_token.value)) if kw_doc is not None and kw_doc.is_any_run_keyword(): for kw_res in self.generate_run_kw_tokens( namespace, diff --git a/packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py b/packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py index aa66fd83..630fc16f 100644 --- a/packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py +++ b/packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py @@ -584,10 +584,11 @@ def _analyze_keyword_call( analyze_run_keywords: bool = True, allow_variables: bool = False, ignore_errors_if_contains_variables: bool = False, + unescape_keyword: bool = True, ) -> Optional[KeywordDoc]: result: Optional[KeywordDoc] = None - keyword = unescape(keyword_token.value) + keyword = unescape(keyword_token.value) if unescape_keyword else keyword_token.value try: lib_entry = None @@ -1008,9 +1009,7 @@ def visit_KeywordCall(self, node: KeywordCall) -> None: # noqa: N802 self._analyze_statement_variables(node) self._analyze_keyword_call( - node, - keyword_token, - [e for e in node.get_tokens(Token.ARGUMENT)], + node, keyword_token, [e for e in node.get_tokens(Token.ARGUMENT)], unescape_keyword=False ) if not self._current_testcase_or_keyword_name: