Skip to content

Commit 34df8c2

Browse files
committed
analysing, highlighting of "Wait Until Keyword Succeeds" and "Repeat Keyword"
1 parent c391deb commit 34df8c2

File tree

6 files changed

+53
-18
lines changed

6 files changed

+53
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ All notable changes to the "robotcode" extension will be documented in this file
55
## [Unreleased]
66

77
### added
8-
- for socket connections now a free port is used
98

9+
- for socket connections now a free port is used
10+
- collect variables and arguments to document symbols
11+
- analysing, highlighting of "Wait Until Keyword Succeeds" and "Repeat Keyword"
12+
1013
## 0.4.0
1114

1215
### added

robotcode/language_server/robotframework/diagnostics/analyzer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,16 @@ async def _analyse_run_keyword(
171171
return argument_tokens[1:]
172172
elif (
173173
keyword_doc.is_run_keyword_with_condition()
174-
and len(argument_tokens) > 1
175-
and is_not_variable_token(argument_tokens[1])
174+
and len(argument_tokens) > (cond_count := keyword_doc.run_keyword_condition_count())
175+
and is_not_variable_token(argument_tokens[cond_count])
176176
):
177177
await self._analyze_keyword_call(
178-
unescape(argument_tokens[1].value), node, argument_tokens[1], argument_tokens[2:]
178+
unescape(argument_tokens[cond_count].value),
179+
node,
180+
argument_tokens[cond_count],
181+
argument_tokens[cond_count + 1 :],
179182
)
180-
return argument_tokens[2:]
183+
return argument_tokens[cond_count + 1 :]
181184
elif keyword_doc.is_run_keywords():
182185
has_and = False
183186
while argument_tokens:

robotcode/language_server/robotframework/diagnostics/library_doc.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,27 @@
6060
"Run Keyword If Test Failed",
6161
"Run Keyword If Test Passed",
6262
"Run Keyword If Timeout Occurred",
63+
"Run Keyword And Warn On Failure",
6364
]
6465

65-
RUN_KEYWORD_WITH_CONDITION_NAMES = ["Run Keyword And Expect Error", "Run Keyword And Return If", "Run Keyword Unless"]
66+
RUN_KEYWORD_WITH_CONDITION_NAMES: Dict[str, int] = {
67+
"Run Keyword And Expect Error": 1,
68+
"Run Keyword And Return If": 1,
69+
"Run Keyword Unless": 1,
70+
"Repeat Keyword": 1,
71+
"Wait Until Keyword Succeeds": 2,
72+
}
6673

6774
RUN_KEYWORD_IF_NAME = "Run Keyword If"
6875

6976
RUN_KEYWORDS_NAME = "Run Keywords"
7077

71-
ALL_RUN_KEYWORDS = [*RUN_KEYWORD_NAMES, *RUN_KEYWORD_WITH_CONDITION_NAMES, RUN_KEYWORDS_NAME, RUN_KEYWORD_IF_NAME]
78+
ALL_RUN_KEYWORDS = [
79+
*RUN_KEYWORD_NAMES,
80+
*RUN_KEYWORD_WITH_CONDITION_NAMES.keys(),
81+
RUN_KEYWORDS_NAME,
82+
RUN_KEYWORD_IF_NAME,
83+
]
7284

7385
BUILTIN_LIBRARY_NAME = "BuiltIn"
7486
RESERVED_LIBRARY_NAME = "Reserved"
@@ -153,7 +165,7 @@ def __repr__(self) -> str:
153165
return f"{type(self).__name__}(name={repr(self.name)})"
154166

155167

156-
RUN_KEYWORD_WITH_CONDITION_MATCHERS = [KeywordMatcher(e) for e in RUN_KEYWORD_WITH_CONDITION_NAMES]
168+
RUN_KEYWORD_WITH_CONDITION_MATCHERS = [KeywordMatcher(e) for e in RUN_KEYWORD_WITH_CONDITION_NAMES.keys()]
157169

158170
RUN_KEYWORD_IF_MATCHER = KeywordMatcher(RUN_KEYWORD_IF_NAME)
159171

@@ -357,7 +369,14 @@ def is_run_keyword(self) -> bool:
357369
return self.libname == BUILTIN_LIBRARY_NAME and self.name in RUN_KEYWORD_NAMES
358370

359371
def is_run_keyword_with_condition(self) -> bool:
360-
return self.libname == BUILTIN_LIBRARY_NAME and self.name in RUN_KEYWORD_WITH_CONDITION_NAMES
372+
return self.libname == BUILTIN_LIBRARY_NAME and self.name in RUN_KEYWORD_WITH_CONDITION_NAMES.keys()
373+
374+
def run_keyword_condition_count(self) -> int:
375+
return (
376+
RUN_KEYWORD_WITH_CONDITION_NAMES[self.name]
377+
if self.libname == BUILTIN_LIBRARY_NAME and self.name in RUN_KEYWORD_WITH_CONDITION_NAMES.keys()
378+
else 0
379+
)
361380

362381
def is_run_keyword_if(self) -> bool:
363382
return self.libname == BUILTIN_LIBRARY_NAME and self.name == RUN_KEYWORD_IF_NAME

robotcode/language_server/robotframework/parts/model_helper.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ async def get_run_keyword_keyworddoc_and_token_from_position(
2929
return result, argument_tokens[1:]
3030
elif (
3131
keyword_doc.is_run_keyword_with_condition()
32-
and len(argument_tokens) > 1
32+
and len(argument_tokens) > (cond_count := keyword_doc.run_keyword_condition_count())
3333
and is_not_variable_token(argument_tokens[1])
3434
):
3535
result = await self.get_keyworddoc_and_token_from_position(
36-
unescape(argument_tokens[1].value), argument_tokens[1], argument_tokens[2:], namespace, position
36+
unescape(argument_tokens[cond_count].value),
37+
argument_tokens[cond_count],
38+
argument_tokens[cond_count + 1 :],
39+
namespace,
40+
position,
3741
)
3842

39-
return result, argument_tokens[2:]
43+
return result, argument_tokens[cond_count + 1 :]
4044

4145
elif keyword_doc.is_run_keywords():
4246
has_and = False

robotcode/language_server/robotframework/parts/references.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,13 @@ async def get_keyword_references_from_any_run_keyword(
421421
namespace, kw_doc, node, arguments[0], arguments[1:]
422422
):
423423
yield e
424-
elif kw.is_run_keyword_with_condition() and len(arguments) > 1 and is_not_variable_token(arguments[1]):
424+
elif (
425+
kw.is_run_keyword_with_condition()
426+
and len(arguments) > (cond_count := kw.run_keyword_condition_count())
427+
and is_not_variable_token(arguments[1])
428+
):
425429
async for e in self.get_keyword_references_from_tokens(
426-
namespace, kw_doc, node, arguments[1], arguments[2:], True
430+
namespace, kw_doc, node, arguments[cond_count], arguments[cond_count + 1 :], True
427431
):
428432
yield e
429433
elif kw.is_run_keywords():

robotcode/language_server/robotframework/parts/semantic_tokens.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,13 @@ async def skip_non_data_tokens() -> AsyncGenerator[Tuple[Token, ast.AST], None]:
384384
):
385385
yield b
386386
elif kw_doc.is_run_keyword_with_condition() and len(arguments) > 0:
387-
yield arguments[0], node,
388-
arguments = arguments[1:]
387+
cond_count = kw_doc.run_keyword_condition_count()
388+
for _ in range(cond_count):
389+
yield arguments[0], node,
390+
arguments = arguments[1:]
389391

390-
async for b in skip_non_data_tokens():
391-
yield b
392+
async for b in skip_non_data_tokens():
393+
yield b
392394

393395
if len(arguments) > 0:
394396
token = arguments[0]

0 commit comments

Comments
 (0)