Skip to content

Commit

Permalink
Properly consider that the Comment keyword doesn't resolve arguments. F…
Browse files Browse the repository at this point in the history
…ixes #665
  • Loading branch information
fabioz committed May 9, 2022
1 parent 76a9e6d commit 686f505
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
10 changes: 10 additions & 0 deletions robotframework-ls/src/robotframework_ls/impl/code_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ def on_unresolved_variable_import(
env_vars_upper = None

for token_info in ast_utils.iter_variable_references(ast):

initial_completion_context.check_cancelled()

if token_info.node.__class__.__name__ in (
Expand All @@ -520,6 +521,15 @@ def on_unresolved_variable_import(
# import.
continue

if (
token_info.node.__class__.__name__ == "KeywordCall"
and token_info.node.keyword == "Comment"
):
# Special handling for 'Comment' keyword (variables are not
# resolved when calling the 'Comment' keyword).
# https://github.com/robocorp/robotframework-lsp/issues/665
continue

var_name = token_info.token.value
var_line = token_info.token.lineno - 1 # We want it 0-based
var_col_offset = token_info.token.col_offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ def _tokenize_token(

# Step 1: cast to KEYWORD if needed.
if use_token_type == ARGUMENT:
in_documentation = node.__class__.__name__ == "Documentation"
in_documentation = node.__class__.__name__ == "Documentation" or (
node.__class__.__name__ == "KeywordCall" and node.keyword == "Comment"
)

if not in_documentation:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,17 @@ def test_empty_var(workspace, libspec_manager, data_regression):
_collect_errors(workspace, doc, data_regression)


def test_comment_keyword_vars(workspace, libspec_manager, data_regression):
workspace.set_root("case2", libspec_manager=libspec_manager)
doc = workspace.put_doc("case2.robot")
doc.source = """
*** Test Cases ***
Check
Comment ${var} Set Variable Test
"""
_collect_errors(workspace, doc, data_regression, basename="no_error")


def test_undefined_reference_default_arg_value(
workspace, libspec_manager, data_regression
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,25 @@ def test_semantic_highlighting_comments(workspace):
)


def test_semantic_highlighting_comment_keyword(workspace):
check_simple(
workspace,
"""*** Test Cases ***
Check
Comment ${var} Set Variable Test
""",
[
("*** Test Cases ***", "header"),
("Check", "testCaseName"),
("Comment", "keywordNameCall"),
("${", "variableOperator"),
("var", "variable"),
("}", "variableOperator"),
(" Set Variable Test", "documentation"),
],
)


def test_semantic_highlighting_catenate(workspace):
check_simple(
workspace,
Expand Down

0 comments on commit 686f505

Please sign in to comment.