Skip to content

Commit 2ffe7b8

Browse files
committed
semantic tokens now highlight run keywords
1 parent 90f65d9 commit 2ffe7b8

File tree

5 files changed

+324
-35
lines changed

5 files changed

+324
-35
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ All notable changes to the "robotcode" extension will be documented in this file
77
### added
88

99
- some refactoring to speedup loading and parsing documents
10-
- semantic tokens now highlight builtin keywords
10+
- semantic tokens now highlight
11+
- builtin keywords
12+
- run keywords
1113
- analysing run keywords now correctly unescape keywords
1214

1315
## 0.3.2

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"id": "builtin",
7272
"description": "built in library, keyword or variable"
7373
}
74-
],
74+
],
7575
"semanticTokenScopes": [
7676
{
7777
"language": "robotframework",
@@ -118,11 +118,14 @@
118118
"variable": [
119119
"variable.other.readwrite.robotframework"
120120
],
121-
"keywordCall": [
122-
"meta.function-call.keyword.robotframework"
121+
"keywordCall": [
122+
"variable.function.keyword-call.robotframework"
123123
],
124-
"nameCall": [
125-
"meta.function-call.name.robotframework"
124+
"keywordCallInner": [
125+
"variable.function.keyword-call.inner.robotframework"
126+
],
127+
"nameCall": [
128+
"variable.function.keyword-call.robotframework"
126129
],
127130
"continuation": [
128131
"punctuation.separator.continuation.robotframework"

robotcode/language_server/robotframework/parts/references.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,16 @@ async def get_keyword_references_from_tokens(
347347
node: ast.AST,
348348
kw_token: Optional[Token],
349349
arguments: Optional[List[Token]],
350+
unescape_kw_token: bool = False,
350351
) -> AsyncGenerator[Location, None]:
352+
from robot.utils.escaping import unescape
353+
351354
if kw_token is not None and is_not_variable_token(kw_token):
352355
kw: Optional[KeywordDoc] = None
353356
kw_matcher = KeywordMatcher(kw_doc.name)
357+
kw_name = unescape(kw_token.value) if unescape_kw_token else kw_token.value
354358

355-
for lib, name in yield_owner_and_kw_names(kw_token.value):
359+
for lib, name in yield_owner_and_kw_names(kw_name):
356360
if lib is not None:
357361
lib_matcher = KeywordMatcher(lib)
358362
if (
@@ -364,7 +368,7 @@ async def get_keyword_references_from_tokens(
364368
if name is not None:
365369
name_matcher = KeywordMatcher(name)
366370
if kw_matcher == name_matcher:
367-
kw = await namespace.find_keyword(str(kw_token.value))
371+
kw = await namespace.find_keyword(kw_name)
368372

369373
if kw is not None and kw == kw_doc:
370374
yield Location(
@@ -386,7 +390,6 @@ async def get_keyword_references_from_any_run_keyword(
386390
kw_token: Token,
387391
arguments: List[Token],
388392
) -> AsyncGenerator[Location, None]:
389-
390393
if kw_token is None or not is_not_variable_token(kw_token):
391394
return
392395

@@ -402,11 +405,11 @@ async def get_keyword_references_from_any_run_keyword(
402405
yield e
403406
elif kw.is_run_keyword_with_condition() and len(arguments) > 1 and is_not_variable_token(arguments[1]):
404407
async for e in self.get_keyword_references_from_tokens(
405-
namespace, kw_doc, node, arguments[1], arguments[2:]
408+
namespace, kw_doc, node, arguments[1], arguments[2:], True
406409
):
407410
yield e
408411
elif kw.is_run_keywords():
409-
412+
has_separator = False
410413
while arguments:
411414

412415
t = arguments[0]
@@ -419,9 +422,13 @@ async def get_keyword_references_from_any_run_keyword(
419422
if separator_token is not None:
420423
args = arguments[: arguments.index(separator_token)]
421424
arguments = arguments[arguments.index(separator_token) + 1 :]
425+
has_separator = True
426+
else:
427+
if has_separator:
428+
args = arguments
422429

423430
if is_not_variable_token(t):
424-
async for e in self.get_keyword_references_from_tokens(namespace, kw_doc, node, t, args):
431+
async for e in self.get_keyword_references_from_tokens(namespace, kw_doc, node, t, args, True):
425432
yield e
426433
elif kw.is_run_keyword_if() and len(arguments) > 1:
427434
arguments = arguments[1:]
@@ -442,7 +449,7 @@ async def get_keyword_references_from_any_run_keyword(
442449
arguments = arguments[1:]
443450

444451
if is_not_variable_token(t):
445-
async for e in self.get_keyword_references_from_tokens(namespace, kw_doc, node, t, args):
452+
async for e in self.get_keyword_references_from_tokens(namespace, kw_doc, node, t, args, True):
446453
yield e
447454

448455
async def _find_keyword_references(self, document: TextDocument, kw_doc: KeywordDoc) -> List[Location]:

0 commit comments

Comments
 (0)