Skip to content

Commit

Permalink
If Run Keyword has a variable concatenated, don't consider it an error.
Browse files Browse the repository at this point in the history
Fixes #534
  • Loading branch information
fabioz committed Jan 19, 2022
1 parent 607ef2f commit cd91022
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions robotframework-ls/src/robotframework_ls/impl/code_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down
25 changes: 24 additions & 1 deletion robotframework-ls/src/robotframework_ls/impl/text_utilities.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cd91022

Please sign in to comment.