Skip to content

Commit 5e1ca88

Browse files
committed
correct handling of templates with embedded arguments
1 parent 343a54a commit 5e1ca88

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to the "robotcode" extension will be documented in this file
1010
- support for progress feature of language server protocol
1111
- correct WHILE snippets
1212
- handle invalid regular expressions in embedded keywords
13+
- correct handling of templates with embedded arguments
1314

1415
## 0.11.6
1516

robotcode/language_server/robotframework/diagnostics/analyzer.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ async def run(self) -> List[Diagnostic]:
5555

5656
async def visit(self, node: ast.AST) -> None:
5757
from robot.parsing.lexer.tokens import Token as RobotToken
58-
from robot.parsing.model.statements import DocumentationOrMetadata, KeywordCall
58+
from robot.parsing.model.statements import (
59+
DocumentationOrMetadata,
60+
KeywordCall,
61+
Template,
62+
TestTemplate,
63+
)
5964
from robot.variables.search import contains_variable
6065

6166
self.node_stack.append(node)
6267
try:
63-
if isinstance(node, HasTokens):
68+
if isinstance(node, HasTokens) and not isinstance(node, (TestTemplate, Template)):
6469
for token in (
6570
t
6671
for t in node.tokens
@@ -185,13 +190,14 @@ async def _analyze_keyword_call(
185190
keyword_token: Token,
186191
argument_tokens: List[Token],
187192
analyse_run_keywords: bool = True,
193+
allow_variables: bool = False,
188194
) -> Optional[KeywordDoc]:
189195
from robot.parsing.model.statements import Template, TestTemplate
190196

191197
result: Optional[KeywordDoc] = None
192198

193199
try:
194-
if not is_not_variable_token(keyword_token):
200+
if not allow_variables and not is_not_variable_token(keyword_token):
195201
return None
196202

197203
result = await self.finder.find_keyword(keyword)
@@ -475,14 +481,10 @@ async def visit_TestTemplate(self, node: ast.AST) -> None: # noqa: N802
475481
value = cast(TestTemplate, node)
476482
keyword_token = cast(Token, value.get_token(RobotToken.NAME))
477483

478-
# TODO: calculate possible variables in NAME
479-
480-
if (
481-
keyword_token is not None
482-
and is_not_variable_token(keyword_token)
483-
and keyword_token.value.upper() not in ("", "NONE")
484-
):
485-
await self._analyze_keyword_call(value.value, value, keyword_token, [])
484+
if keyword_token is not None and keyword_token.value.upper() not in ("", "NONE"):
485+
await self._analyze_keyword_call(
486+
value.value, value, keyword_token, [], analyse_run_keywords=False, allow_variables=True
487+
)
486488

487489
self.test_template = value
488490
await self.generic_visit(node)
@@ -494,14 +496,10 @@ async def visit_Template(self, node: ast.AST) -> None: # noqa: N802
494496
value = cast(Template, node)
495497
keyword_token = cast(Token, value.get_token(RobotToken.NAME))
496498

497-
# TODO: calculate possible variables in NAME
498-
499-
if (
500-
keyword_token is not None
501-
and is_not_variable_token(keyword_token)
502-
and keyword_token.value.upper() not in ("", "NONE")
503-
):
504-
await self._analyze_keyword_call(value.value, value, keyword_token, [])
499+
if keyword_token is not None and keyword_token.value.upper() not in ("", "NONE"):
500+
await self._analyze_keyword_call(
501+
value.value, value, keyword_token, [], analyse_run_keywords=False, allow_variables=True
502+
)
505503

506504
await self.generic_visit(node)
507505

0 commit comments

Comments
 (0)