Skip to content

Commit c12e1ef

Browse files
committed
fix(langserver): correct highlighting of keyword arguments with default value
1 parent b9cd85a commit c12e1ef

File tree

1 file changed

+27
-6
lines changed
  • packages/language_server/src/robotcode/language_server/robotframework/parts

1 file changed

+27
-6
lines changed

packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ async def generate_sem_sub_tokens(
277277
) -> AsyncIterator[SemTokenInfo]:
278278
from robot.parsing.lexer.tokens import Token as RobotToken
279279
from robot.parsing.model.statements import (
280-
Arguments,
281280
Documentation,
282281
Fixture,
283282
LibraryImport,
@@ -309,7 +308,7 @@ async def generate_sem_sub_tokens(
309308

310309
yield SemTokenInfo.from_token(
311310
token,
312-
SemanticTokenTypes.PARAMETER if isinstance(node, Arguments) else sem_type,
311+
sem_type,
313312
sem_mod,
314313
col_offset + 2,
315314
last_index - 2,
@@ -497,24 +496,46 @@ async def generate_sem_tokens(
497496
resources_matchers: Dict[KeywordMatcher, ResourceEntry],
498497
) -> AsyncIterator[SemTokenInfo]:
499498
from robot.parsing.lexer.tokens import Token as RobotToken
500-
from robot.parsing.model.statements import Variable
499+
from robot.parsing.model.statements import Arguments, Variable
501500
from robot.utils.escaping import split_from_equals
502501

503502
if token.type in {RobotToken.ARGUMENT, RobotToken.TESTCASE_NAME, RobotToken.KEYWORD_NAME}:
504-
if isinstance(node, Variable) and token.type == RobotToken.ARGUMENT and node.name and node.name[0] == "&":
503+
if (
504+
isinstance(node, Variable) and token.type == RobotToken.ARGUMENT and node.name and node.name[0] == "&"
505+
) or (isinstance(node, Arguments)):
505506
name, value = split_from_equals(token.value)
506507
if value is not None:
507508
length = len(name)
508509

509510
yield SemTokenInfo.from_token(
510-
RobotToken(ROBOT_NAMED_ARGUMENT, name, token.lineno, token.col_offset),
511-
RobotSemTokenTypes.NAMED_ARGUMENT,
511+
RobotToken(
512+
ROBOT_NAMED_ARGUMENT if isinstance(node, Variable) else SemanticTokenTypes.PARAMETER,
513+
name,
514+
token.lineno,
515+
token.col_offset,
516+
),
517+
RobotSemTokenTypes.NAMED_ARGUMENT
518+
if isinstance(node, Variable)
519+
else SemanticTokenTypes.PARAMETER,
512520
)
513521
yield SemTokenInfo.from_token(
514522
RobotToken(ROBOT_OPERATOR, "=", token.lineno, token.col_offset + length),
515523
SemanticTokenTypes.OPERATOR,
516524
)
517525
token = RobotToken(token.type, value, token.lineno, token.col_offset + length + 1, token.error)
526+
elif isinstance(node, Arguments) and name:
527+
yield SemTokenInfo.from_token(
528+
RobotToken(
529+
ROBOT_NAMED_ARGUMENT if isinstance(node, Variable) else SemanticTokenTypes.PARAMETER,
530+
name,
531+
token.lineno,
532+
token.col_offset,
533+
),
534+
RobotSemTokenTypes.NAMED_ARGUMENT
535+
if isinstance(node, Variable)
536+
else SemanticTokenTypes.PARAMETER,
537+
)
538+
token = RobotToken(token.type, "", token.lineno, token.col_offset + len(name), token.error)
518539

519540
for sub_token in self._tokenize_variables(
520541
token,

0 commit comments

Comments
 (0)