Skip to content

Commit 35526a0

Browse files
committed
feat(analyzer): support for types in embedded arguments
1 parent 94cdc54 commit 35526a0

File tree

51 files changed

+1953
-1442
lines changed

Some content is hidden

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

51 files changed

+1953
-1442
lines changed

packages/robot/src/robotcode/robot/diagnostics/entities.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ def __hash__(self) -> int:
275275
return hash((type(self), self.name, self.type, self.range, self.source))
276276

277277

278+
@dataclass
279+
class EmbeddedArgumentDefinition(ArgumentDefinition):
280+
pattern: Optional[str] = field(default=None, compare=False)
281+
282+
@single_call
283+
def __hash__(self) -> int:
284+
return hash((type(self), self.name, self.type, self.range, self.source))
285+
286+
278287
@dataclass
279288
class LibraryArgumentDefinition(ArgumentDefinition):
280289
@single_call

packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ast
22
import functools
33
import os
4+
import re
45
import token as python_token
56
from collections import defaultdict
67
from concurrent.futures import CancelledError
@@ -64,6 +65,7 @@
6465
from ..utils.visitor import Visitor
6566
from .entities import (
6667
ArgumentDefinition,
68+
EmbeddedArgumentDefinition,
6769
EnvironmentVariableDefinition,
6870
GlobalVariableDefinition,
6971
LibraryEntry,
@@ -1135,6 +1137,8 @@ def visit_Keyword(self, node: Keyword) -> None: # noqa: N802
11351137
self._current_testcase_or_keyword_name = None
11361138
self._current_keyword_doc = None
11371139

1140+
EMBEDDED_ARGUMENTS_MATCHER = re.compile("([^:]+): ([^:]+)(:(.*))?")
1141+
11381142
def visit_KeywordName(self, node: KeywordName) -> None: # noqa: N802
11391143
name_token = node.get_token(Token.KEYWORD_NAME)
11401144

@@ -1144,14 +1148,28 @@ def visit_KeywordName(self, node: KeywordName) -> None: # noqa: N802
11441148
tokenize_variables(name_token, identifiers="$", ignore_errors=True),
11451149
):
11461150
if variable_token.value:
1147-
match = search_variable(variable_token.value, "$", ignore_errors=True)
1148-
if match.base is None:
1151+
matcher = search_variable(variable_token.value, "$", ignore_errors=True)
1152+
if matcher.base is None:
11491153
continue
1150-
name = match.base.split(":", 1)[0]
1151-
full_name = f"{match.identifier}{{{name}}}"
1154+
if ":" not in matcher.base:
1155+
name = matcher.base
1156+
pattern = None
1157+
type = None
1158+
elif get_robot_version() >= (7, 3):
1159+
re_match = self.EMBEDDED_ARGUMENTS_MATCHER.fullmatch(matcher.base)
1160+
if re_match:
1161+
name, type, _, pattern = re_match.groups()
1162+
else:
1163+
name, pattern = matcher.base.split(":", 1)
1164+
type = None
1165+
else:
1166+
name, pattern = matcher.base.split(":", 1)
1167+
type = None
1168+
1169+
full_name = f"{matcher.identifier}{{{name}}}"
11521170
var_token = strip_variable_token(variable_token)
11531171
var_token.value = name
1154-
arg_def = ArgumentDefinition(
1172+
arg_def = EmbeddedArgumentDefinition(
11551173
name=full_name,
11561174
name_token=var_token,
11571175
line_no=variable_token.lineno,
@@ -1160,6 +1178,8 @@ def visit_KeywordName(self, node: KeywordName) -> None: # noqa: N802
11601178
end_col_offset=variable_token.end_col_offset,
11611179
source=self._namespace.source,
11621180
keyword_doc=self._current_keyword_doc,
1181+
value_type=type,
1182+
pattern=pattern,
11631183
)
11641184

11651185
self._variables[arg_def.matcher] = arg_def

tests/robotcode/language_server/robotframework/parts/_regtest_outputs/rf41/test_references.test[references.robot-036-004-simple_keyword_call].out

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,6 @@ result:
219219
character: 4
220220
line: 55
221221
uri: rf70/vartest.robot
222-
- !Location
223-
range:
224-
end:
225-
character: 7
226-
line: 10
227-
start:
228-
character: 4
229-
line: 10
230-
uri: rf73/variable_conversion.robot
231222
- !Location
232223
range:
233224
end:
@@ -277,10 +268,10 @@ result:
277268
range:
278269
end:
279270
character: 7
280-
line: 25
271+
line: 16
281272
start:
282273
character: 4
283-
line: 25
274+
line: 16
284275
uri: rf73/variable_conversion.robot
285276
- !Location
286277
range:
@@ -295,109 +286,118 @@ result:
295286
range:
296287
end:
297288
character: 7
298-
line: 30
289+
line: 27
299290
start:
300291
character: 4
301-
line: 30
292+
line: 27
293+
uri: rf73/variable_conversion.robot
294+
- !Location
295+
range:
296+
end:
297+
character: 7
298+
line: 31
299+
start:
300+
character: 4
301+
line: 31
302302
uri: rf73/variable_conversion.robot
303303
- !Location
304304
range:
305305
end:
306306
character: 11
307-
line: 36
307+
line: 37
308308
start:
309309
character: 8
310-
line: 36
310+
line: 37
311311
uri: rf73/variable_conversion.robot
312312
- !Location
313313
range:
314314
end:
315315
character: 11
316-
line: 40
316+
line: 41
317317
start:
318318
character: 8
319-
line: 40
319+
line: 41
320320
uri: rf73/variable_conversion.robot
321321
- !Location
322322
range:
323323
end:
324324
character: 7
325-
line: 45
325+
line: 46
326326
start:
327327
character: 4
328-
line: 45
328+
line: 46
329329
uri: rf73/variable_conversion.robot
330330
- !Location
331331
range:
332332
end:
333333
character: 7
334-
line: 55
334+
line: 57
335335
start:
336336
character: 4
337-
line: 55
337+
line: 57
338338
uri: rf73/variable_conversion.robot
339339
- !Location
340340
range:
341341
end:
342342
character: 7
343-
line: 56
343+
line: 58
344344
start:
345345
character: 4
346-
line: 56
346+
line: 58
347347
uri: rf73/variable_conversion.robot
348348
- !Location
349349
range:
350350
end:
351351
character: 7
352-
line: 57
352+
line: 59
353353
start:
354354
character: 4
355-
line: 57
355+
line: 59
356356
uri: rf73/variable_conversion.robot
357357
- !Location
358358
range:
359359
end:
360360
character: 7
361-
line: 58
361+
line: 60
362362
start:
363363
character: 4
364-
line: 58
364+
line: 60
365365
uri: rf73/variable_conversion.robot
366366
- !Location
367367
range:
368368
end:
369369
character: 7
370-
line: 62
370+
line: 64
371371
start:
372372
character: 4
373-
line: 62
373+
line: 64
374374
uri: rf73/variable_conversion.robot
375375
- !Location
376376
range:
377377
end:
378378
character: 7
379-
line: 63
379+
line: 65
380380
start:
381381
character: 4
382-
line: 63
382+
line: 65
383383
uri: rf73/variable_conversion.robot
384384
- !Location
385385
range:
386386
end:
387387
character: 7
388-
line: 67
388+
line: 69
389389
start:
390390
character: 4
391-
line: 67
391+
line: 69
392392
uri: rf73/variable_conversion.robot
393393
- !Location
394394
range:
395395
end:
396396
character: 7
397-
line: 81
397+
line: 83
398398
start:
399399
character: 4
400-
line: 81
400+
line: 83
401401
uri: rf73/variable_conversion.robot
402402
- !Location
403403
range:

0 commit comments

Comments
 (0)