Skip to content

Commit c56def3

Browse files
committed
feat(vscode): python syntax highlightning in IF and WHILE statements
implements a part of #230
1 parent 8936bfb commit c56def3

File tree

92 files changed

+1795
-13544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1795
-13544
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,14 @@ def generate_sem_sub_tokens(
403403
col_offset = token.col_offset
404404

405405
for g in cls.ESCAPE_REGEX.finditer(token.value):
406-
yield SemTokenInfo.from_token(
407-
token,
408-
sem_type if g.group("x") is None else RobotSemTokenTypes.ESCAPE,
409-
sem_mod,
410-
col_offset + g.start(),
411-
g.end() - g.start(),
412-
)
406+
if g.group("x") is not None:
407+
yield SemTokenInfo.from_token(
408+
token,
409+
sem_type if g.group("x") is None else RobotSemTokenTypes.ESCAPE,
410+
sem_mod,
411+
col_offset + g.start(),
412+
g.end() - g.start(),
413+
)
413414
elif token.type in [Token.KEYWORD, ROBOT_KEYWORD_INNER] or (
414415
token.type == Token.NAME and isinstance(node, (Fixture, Template, TestTemplate))
415416
):
@@ -614,7 +615,8 @@ def generate_sem_sub_tokens(
614615
1,
615616
)
616617
else:
617-
yield SemTokenInfo.from_token(token, sem_type, sem_mod, col_offset, length)
618+
if token.type != Token.ARGUMENT:
619+
yield SemTokenInfo.from_token(token, sem_type, sem_mod, col_offset, length)
618620

619621
def generate_sem_tokens(
620622
self,

syntaxes/robotframework.tmLanguage.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,48 @@
111111
{ "include": "#line_continuation" }
112112
]
113113
},
114+
"control_flow_expression_statements": {
115+
"name": "meta.keyword-call.content.robotframework",
116+
"contentName": "string.unquoted.argument.robotframework",
117+
"begin": "^(?!(?: {2,}| ?\\t ?)+(?:(?=[$\\[@&%]|\\.)))(?: {2,}| ?\\t ?)+(IF|ELSE IF|WHILE)(( {2,}| ?\\t)( *)(.*?))?(?= {2,}| ?\\t ?| ?$)",
118+
"end": "^(?!\\s*\\.\\.\\.)",
119+
"beginCaptures": {
120+
"1": { "name": "keyword.control.flow.robotframework" },
121+
"5": {
122+
"name": "meta.python-expression.robotframework",
123+
"patterns": [ { "include": "#expression" } ]
124+
}
125+
},
126+
"patterns": [
127+
{ "include": "#comment" },
128+
{ "include": "#variables" },
129+
{ "include": "#line_continuation" }
130+
]
131+
},
132+
"control_flow_statements": {
133+
"name": "meta.keyword-call.content.robotframework",
134+
"contentName": "string.unquoted.argument.robotframework",
135+
"begin": "^(?!(?: {2,}| ?\\t ?)+(?:(?=[$\\[@&%]|\\.)))(?: {2,}| ?\\t ?)+(FOR|END|ELSE|TRY|EXCEPT|FINALLY)(?= {2,}| ?\\t ?| ?$)",
136+
"end": "^(?!\\s*\\.\\.\\.)",
137+
"beginCaptures": { "1": { "name": "keyword.control.flow.robotframework" } },
138+
"patterns": [
139+
{ "include": "#comment" },
140+
{ "include": "#variables" },
141+
{ "include": "#line_continuation" }
142+
]
143+
},
144+
"other_statements": {
145+
"name": "meta.keyword-call.content.robotframework",
146+
"contentName": "string.unquoted.argument.robotframework",
147+
"begin": "^(?!(?: {2,}| ?\\t ?)+(?:(?=[$\\[@&%]|\\.)))(?: {2,}| ?\\t ?)+(VAR)(?= {2,}| ?\\t ?| ?$)",
148+
"end": "^(?!\\s*\\.\\.\\.)",
149+
"beginCaptures": { "1": { "name": "keyword.robotframework" } },
150+
"patterns": [
151+
{ "include": "#comment" },
152+
{ "include": "#variables" },
153+
{ "include": "#line_continuation" }
154+
]
155+
},
114156
"returning_keyword_call": {
115157
"name": "meta.returning-keyword-call.robotframework",
116158
"contentName": "meta.returning.keyword.content.robotframework",
@@ -2278,6 +2320,9 @@
22782320
{ "include": "#variable_setting" },
22792321
{ "include": "#setting" },
22802322
{ "include": "#testcase_settings" },
2323+
{ "include": "#control_flow_expression_statements" },
2324+
{ "include": "#control_flow_statements" },
2325+
{ "include": "#other_statements" },
22812326
{ "include": "#keyword_call" },
22822327
{ "include": "#returning_keyword_call" }
22832328
],

tests/robotcode/language_server/robotframework/parts/_regtest_outputs/rf41/test_semantic_tokens.test[bddstyle.robot].out

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,6 @@ result: !SemanticTokens
245245
- 2
246246
- 39
247247
- 0
248-
- 0
249-
- 6
250-
- 1
251-
- 36
252-
- 0
253-
- 0
254-
- 9
255-
- 1
256-
- 36
257-
- 0
258-
- 0
259-
- 9
260-
- 1
261-
- 36
262-
- 0
263248
- 1
264249
- 0
265250
- 10
@@ -270,21 +255,6 @@ result: !SemanticTokens
270255
- 2
271256
- 39
272257
- 0
273-
- 0
274-
- 6
275-
- 1
276-
- 36
277-
- 0
278-
- 0
279-
- 9
280-
- 1
281-
- 36
282-
- 0
283-
- 0
284-
- 9
285-
- 1
286-
- 36
287-
- 0
288258
- 1
289259
- 0
290260
- 10
@@ -295,19 +265,4 @@ result: !SemanticTokens
295265
- 2
296266
- 39
297267
- 0
298-
- 0
299-
- 6
300-
- 1
301-
- 36
302-
- 0
303-
- 0
304-
- 9
305-
- 1
306-
- 36
307-
- 0
308-
- 0
309-
- 9
310-
- 2
311-
- 36
312-
- 0
313268
result_id: null

0 commit comments

Comments
 (0)