Skip to content

Commit ec2c444

Browse files
committed
fix(robotlangserver): try to hover, goto, ... for keyword with variables in names
1 parent d8b23e4 commit ec2c444

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

robotcode/language_server/robotframework/parts/model_helper.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from ..diagnostics.namespace import DEFAULT_BDD_PREFIXES, LibraryEntry, Namespace
2424
from ..utils.ast_utils import (
2525
Token,
26-
is_not_variable_token,
2726
iter_over_keyword_names_and_owners,
2827
range_from_token,
2928
strip_variable_token,
@@ -46,16 +45,14 @@ async def get_run_keyword_keyworddoc_and_token_from_position(
4645
if keyword_doc is None or not keyword_doc.is_any_run_keyword():
4746
return None, argument_tokens
4847

49-
if keyword_doc.is_run_keyword() and len(argument_tokens) > 0 and is_not_variable_token(argument_tokens[0]):
48+
if keyword_doc.is_run_keyword() and len(argument_tokens) > 0:
5049
result = await cls.get_keyworddoc_and_token_from_position(
5150
unescape(argument_tokens[0].value), argument_tokens[0], argument_tokens[1:], namespace, position
5251
)
5352

5453
return result, argument_tokens[1:]
55-
elif (
56-
keyword_doc.is_run_keyword_with_condition()
57-
and len(argument_tokens) > (cond_count := keyword_doc.run_keyword_condition_count())
58-
and is_not_variable_token(argument_tokens[1])
54+
elif keyword_doc.is_run_keyword_with_condition() and len(argument_tokens) > (
55+
cond_count := keyword_doc.run_keyword_condition_count()
5956
):
6057
result = await cls.get_keyworddoc_and_token_from_position(
6158
unescape(argument_tokens[cond_count].value),
@@ -107,11 +104,7 @@ def skip_args() -> None:
107104
break
108105
argument_tokens = argument_tokens[1:]
109106

110-
inner_keyword_doc = (
111-
await namespace.find_keyword(argument_tokens[1].value)
112-
if is_not_variable_token(argument_tokens[1])
113-
else None
114-
)
107+
inner_keyword_doc = await namespace.find_keyword(argument_tokens[1].value, raise_keyword_error=False)
115108

116109
if position.is_in_range(range_from_token(argument_tokens[1])):
117110
return (inner_keyword_doc, argument_tokens[1]), argument_tokens[2:]

robotcode/language_server/robotframework/parts/semantic_tokens.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
from ..utils.ast_utils import (
5252
HasTokens,
5353
Token,
54-
is_not_variable_token,
5554
iter_over_keyword_names_and_owners,
5655
token_in_range,
5756
)
@@ -545,7 +544,7 @@ async def skip_non_data_tokens() -> AsyncGenerator[Tuple[Token, ast.AST], None]:
545544
builtin_library_doc,
546545
libraries_matchers,
547546
resources_matchers,
548-
await namespace.find_keyword(unescape(token.value)) if is_not_variable_token(token) else None,
547+
await namespace.find_keyword(unescape(token.value), raise_keyword_error=False),
549548
RobotToken(ROBOT_KEYWORD_INNER, token.value, token.lineno, token.col_offset, token.error),
550549
arguments[1:],
551550
node,
@@ -567,7 +566,7 @@ async def skip_non_data_tokens() -> AsyncGenerator[Tuple[Token, ast.AST], None]:
567566
builtin_library_doc,
568567
libraries_matchers,
569568
resources_matchers,
570-
await namespace.find_keyword(unescape(token.value)) if is_not_variable_token(token) else None,
569+
await namespace.find_keyword(unescape(token.value), raise_keyword_error=False),
571570
RobotToken(ROBOT_KEYWORD_INNER, token.value, token.lineno, token.col_offset, token.error),
572571
arguments[1:],
573572
node,
@@ -607,7 +606,7 @@ async def skip_non_data_tokens() -> AsyncGenerator[Tuple[Token, ast.AST], None]:
607606
builtin_library_doc,
608607
libraries_matchers,
609608
resources_matchers,
610-
await namespace.find_keyword(unescape(token.value)) if is_not_variable_token(token) else None,
609+
await namespace.find_keyword(unescape(token.value), raise_keyword_error=False),
611610
RobotToken(ROBOT_KEYWORD_INNER, token.value, token.lineno, token.col_offset, token.error),
612611
args,
613612
node,
@@ -647,11 +646,7 @@ async def generate_run_kw_if() -> AsyncGenerator[Tuple[Token, ast.AST], None]:
647646
arguments = arguments[1:]
648647
continue
649648

650-
inner_kw_doc = (
651-
await namespace.find_keyword(unescape(token.value))
652-
if is_not_variable_token(token)
653-
else None
654-
)
649+
inner_kw_doc = await namespace.find_keyword(unescape(token.value), raise_keyword_error=False)
655650

656651
if inner_kw_doc is not None and inner_kw_doc.is_run_keyword_if():
657652
yield RobotToken(

0 commit comments

Comments
 (0)