Skip to content

Commit 8687bec

Browse files
committed
correctly find keyword with '.' in name, highlight variables in inner keywords, some renaming
1 parent 680b698 commit 8687bec

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

robotcode/language_server/robotframework/parts/references.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
get_nodes_at_position,
4040
get_tokens_at_position,
4141
is_not_variable_token,
42+
iter_over_keyword_names_and_owners,
4243
range_from_token,
4344
range_from_token_or_node,
4445
tokenize_variables,
45-
yield_owner_and_kw_names,
4646
)
4747
from ..utils.async_ast import iter_nodes
4848

@@ -356,7 +356,7 @@ async def get_keyword_references_from_tokens(
356356
kw_matcher = KeywordMatcher(kw_doc.name)
357357
kw_name = unescape(kw_token.value) if unescape_kw_token else kw_token.value
358358

359-
for lib, name in yield_owner_and_kw_names(kw_name):
359+
for lib, name in iter_over_keyword_names_and_owners(kw_name):
360360
if lib is not None:
361361
lib_matcher = KeywordMatcher(lib)
362362
if (

robotcode/language_server/robotframework/parts/semantic_tokens.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
Token,
4949
is_not_variable_token,
5050
iter_nodes,
51+
iter_over_keyword_names_and_owners,
5152
token_in_range,
5253
tokenize_variables,
53-
yield_owner_and_kw_names,
5454
)
5555

5656
if TYPE_CHECKING:
@@ -265,7 +265,7 @@ async def generate_sem_sub_tokens(
265265
kw_namespace: Optional[str] = None
266266
kw: str = token.value
267267

268-
for lib, name in yield_owner_and_kw_names(token.value):
268+
for lib, name in iter_over_keyword_names_and_owners(token.value):
269269
if lib is not None:
270270
lib_matcher = KeywordMatcher(lib)
271271
if (
@@ -319,10 +319,13 @@ async def generate_sem_tokens(
319319
) -> AsyncGenerator[SemTokenInfo, None]:
320320
from robot.parsing.lexer.tokens import Token as RobotToken
321321

322-
if token.type in {*RobotToken.ALLOW_VARIABLES, RobotToken.KEYWORD}:
322+
if token.type in {*RobotToken.ALLOW_VARIABLES, RobotToken.KEYWORD, ROBOT_KEYWORD_INNER}:
323323

324324
for sub_token in tokenize_variables(
325-
token, ignore_errors=True, identifiers="$" if token.type == RobotToken.KEYWORD_NAME else "$@&%"
325+
token,
326+
ignore_errors=True,
327+
identifiers="$" if token.type == RobotToken.KEYWORD_NAME else "$@&%",
328+
extra_types={ROBOT_KEYWORD_INNER},
326329
):
327330
async for e in self.generate_sem_sub_tokens(namespace, builtin_library_doc, sub_token, node):
328331
yield e
@@ -535,7 +538,7 @@ async def get_tokens() -> AsyncGenerator[Tuple[Token, ast.AST], None]:
535538
)
536539
kw: Optional[str] = None
537540

538-
for _, name in yield_owner_and_kw_names(kw_token.value):
541+
for _, name in iter_over_keyword_names_and_owners(kw_token.value):
539542
if name is not None:
540543
matcher = KeywordMatcher(name)
541544
if matcher in ALL_RUN_KEYWORDS_MATCHERS:

robotcode/language_server/robotframework/utils/ast.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
List,
1010
Optional,
1111
Protocol,
12+
Set,
1213
Tuple,
1314
runtime_checkable,
1415
)
@@ -195,12 +196,17 @@ def _tokenize_no_variables(token: Token) -> Generator[Token, None, None]:
195196

196197

197198
def tokenize_variables(
198-
token: Token, identifiers: str = "$@&%", ignore_errors: bool = False
199+
token: Token, identifiers: str = "$@&%", ignore_errors: bool = False, *, extra_types: Optional[Set[str]] = None
199200
) -> Generator[Token, Any, Any]:
200201
from robot.api.parsing import Token as RobotToken
201202
from robot.variables import VariableIterator
202203

203-
if token.type not in {*RobotToken.ALLOW_VARIABLES, RobotToken.KEYWORD, RobotToken.ASSIGN}:
204+
if token.type not in {
205+
*RobotToken.ALLOW_VARIABLES,
206+
RobotToken.KEYWORD,
207+
RobotToken.ASSIGN,
208+
*(extra_types if extra_types is not None else set()),
209+
}:
204210
return _tokenize_no_variables(token)
205211
variables = VariableIterator(token.value, identifiers=identifiers, ignore_errors=ignore_errors)
206212
if not variables:
@@ -224,7 +230,9 @@ def _tokenize_variables(token: Token, variables: Any) -> Generator[Token, Any, A
224230
yield RobotToken(token.type, remaining, lineno, col_offset)
225231

226232

227-
def yield_owner_and_kw_names(full_name: str) -> Iterator[Tuple[Optional[str], ...]]:
233+
def iter_over_keyword_names_and_owners(full_name: str) -> Iterator[Tuple[Optional[str], ...]]:
234+
yield None, full_name
235+
228236
tokens = full_name.split(".")
229237
if len(tokens) == 1:
230238
yield None, tokens[0]

0 commit comments

Comments
 (0)