diff --git a/robotframework-ls/src/robotframework_ls/impl/code_analysis.py b/robotframework-ls/src/robotframework_ls/impl/code_analysis.py index caecee370d..93a3b73b6a 100644 --- a/robotframework-ls/src/robotframework_ls/impl/code_analysis.py +++ b/robotframework-ls/src/robotframework_ls/impl/code_analysis.py @@ -114,7 +114,7 @@ def collect_analysis_errors(completion_context): from robotframework_ls.impl.ast_utils import create_error_from_node from robotframework_ls.impl.collect_keywords import collect_keywords from robotframework_ls.impl.text_utilities import normalize_robot_name - from robotframework_ls.impl.text_utilities import is_variable_text + from robotframework_ls.impl.text_utilities import contains_variable_text errors = [] collector = _KeywordsCollector() @@ -125,7 +125,7 @@ def collect_analysis_errors(completion_context): ast, collect_args_as_keywords=True ): completion_context.check_cancelled() - if is_variable_text(keyword_usage_info.name): + if contains_variable_text(keyword_usage_info.name): continue normalized_name = normalize_robot_name(keyword_usage_info.name) if not collector.contains_keyword(normalized_name): diff --git a/robotframework-ls/src/robotframework_ls/impl/text_utilities.py b/robotframework-ls/src/robotframework_ls/impl/text_utilities.py index 20329f06eb..90aba8f414 100644 --- a/robotframework-ls/src/robotframework_ls/impl/text_utilities.py +++ b/robotframework-ls/src/robotframework_ls/impl/text_utilities.py @@ -1,4 +1,7 @@ from functools import lru_cache +from robocorp_ls_core.robotframework_log import get_logger + +log = get_logger(__name__) class TextUtilities(object): @@ -32,7 +35,7 @@ def normalize_robot_name(text): return text.lower().replace("_", "").replace(" ", "") -def is_variable_text(text): +def is_variable_text(text: str) -> bool: from robotframework_ls.impl import robot_constants for p in robot_constants.VARIABLE_PREFIXES: @@ -41,6 +44,26 @@ def is_variable_text(text): return False +def contains_variable_text(text: str) -> bool: + if "{" not in text: + return False + + from robotframework_ls.impl import ast_utils + + token = ast_utils.create_token(text) + + try: + tokenized_vars = ast_utils.tokenize_variables(token) + for v in tokenized_vars: + if v.type == v.VARIABLE: + return True + + except: + log.debug("Error tokenizing to variables: %s", text) + + return False + + def matches_robot_keyword(keyword_name_call_text, keyword_name, _re_cache={}): """ Checks if a given text matches a given keyword. diff --git a/robotframework-ls/tests/robotframework_ls_tests/test_code_analysis.py b/robotframework-ls/tests/robotframework_ls_tests/test_code_analysis.py index aca84db45f..d36e5454b1 100644 --- a/robotframework-ls/tests/robotframework_ls_tests/test_code_analysis.py +++ b/robotframework-ls/tests/robotframework_ls_tests/test_code_analysis.py @@ -98,6 +98,7 @@ def test_keywords_in_args_no_error_with_var( doc.source + """ Run Keyword ${var} + Run Keyword concat with ${var} """ ) doc = workspace.put_doc("case1.robot", new_source)