@@ -141,12 +141,19 @@ async def visit_Variable(self, node: ast.AST) -> None: # noqa: N802
141
141
142
142
143
143
class BlockVariableVisitor (AsyncVisitor ):
144
- async def get (self , source : str , model : ast .AST , position : Optional [Position ] = None ) -> List [VariableDefinition ]:
144
+ def __init__ (self , source : str , position : Optional [Position ] = None , in_args : bool = True ) -> None :
145
+ super ().__init__ ()
146
+
145
147
self .source = source
146
148
self .position = position
149
+ self .in_args = in_args
147
150
148
151
self ._results : Dict [str , VariableDefinition ] = {}
149
152
153
+ async def get (self , model : ast .AST ) -> List [VariableDefinition ]:
154
+
155
+ self ._results = {}
156
+
150
157
await self .visit (model )
151
158
152
159
return list (self ._results .values ())
@@ -178,10 +185,10 @@ async def visit_KeywordName(self, node: ast.AST) -> None: # noqa: N802
178
185
self ._results [name ] = ArgumentDefinition (
179
186
name = name ,
180
187
name_token = strip_variable_token (variable_token ),
181
- line_no = n .lineno ,
182
- col_offset = n .col_offset ,
183
- end_line_no = n .lineno ,
184
- end_col_offset = n .end_col_offset ,
188
+ line_no = variable_token .lineno ,
189
+ col_offset = variable_token .col_offset ,
190
+ end_line_no = variable_token .lineno ,
191
+ end_col_offset = variable_token .end_col_offset ,
185
192
source = self .source ,
186
193
)
187
194
@@ -212,13 +219,16 @@ async def visit_Arguments(self, node: ast.AST) -> None: # noqa: N802
212
219
argument = self .get_variable_token (argument_token )
213
220
214
221
if argument is not None :
222
+ if self .in_args and self .position is not None and self .position > range_from_token (argument ).end :
223
+ break
224
+
215
225
self ._results [argument .value ] = ArgumentDefinition (
216
226
name = argument .value ,
217
227
name_token = strip_variable_token (argument ),
218
- line_no = n .lineno ,
219
- col_offset = n .col_offset ,
220
- end_line_no = n .lineno ,
221
- end_col_offset = n .end_col_offset ,
228
+ line_no = argument .lineno ,
229
+ col_offset = argument .col_offset ,
230
+ end_line_no = argument .lineno ,
231
+ end_col_offset = argument .end_col_offset ,
222
232
source = self .source ,
223
233
)
224
234
@@ -241,10 +251,10 @@ async def visit_ExceptHeader(self, node: ast.AST) -> None: # noqa: N802
241
251
self ._results [variable .value ] = LocalVariableDefinition (
242
252
name = variable .value ,
243
253
name_token = strip_variable_token (variable ),
244
- line_no = n .lineno ,
245
- col_offset = n .col_offset ,
246
- end_line_no = n .lineno ,
247
- end_col_offset = n .end_col_offset ,
254
+ line_no = variable .lineno ,
255
+ col_offset = variable .col_offset ,
256
+ end_line_no = variable .lineno ,
257
+ end_col_offset = variable .end_col_offset ,
248
258
source = self .source ,
249
259
)
250
260
@@ -276,10 +286,10 @@ async def visit_KeywordCall(self, node: ast.AST) -> None: # noqa: N802
276
286
self ._results [variable_token .value ] = LocalVariableDefinition (
277
287
name = variable_token .value ,
278
288
name_token = strip_variable_token (variable_token ),
279
- line_no = n .lineno ,
280
- col_offset = n .col_offset ,
281
- end_line_no = n .lineno ,
282
- end_col_offset = n .end_col_offset ,
289
+ line_no = variable_token .lineno ,
290
+ col_offset = variable_token .col_offset ,
291
+ end_line_no = variable_token .lineno ,
292
+ end_col_offset = variable_token .end_col_offset ,
283
293
source = self .source ,
284
294
)
285
295
@@ -311,10 +321,10 @@ async def visit_InlineIfHeader(self, node: ast.AST) -> None: # noqa: N802
311
321
self ._results [variable_token .value ] = LocalVariableDefinition (
312
322
name = variable_token .value ,
313
323
name_token = strip_variable_token (variable_token ),
314
- line_no = n .lineno ,
315
- col_offset = n .col_offset ,
316
- end_line_no = n .lineno ,
317
- end_col_offset = n .end_col_offset ,
324
+ line_no = variable_token .lineno ,
325
+ col_offset = variable_token .col_offset ,
326
+ end_line_no = variable_token .lineno ,
327
+ end_col_offset = variable_token .end_col_offset ,
318
328
source = self .source ,
319
329
)
320
330
@@ -333,10 +343,10 @@ async def visit_ForHeader(self, node: ast.AST) -> None: # noqa: N802
333
343
self ._results [variable_token .value ] = LocalVariableDefinition (
334
344
name = variable_token .value ,
335
345
name_token = strip_variable_token (variable_token ),
336
- line_no = n .lineno ,
337
- col_offset = n .col_offset ,
338
- end_line_no = n .lineno ,
339
- end_col_offset = n .end_col_offset ,
346
+ line_no = variable_token .lineno ,
347
+ col_offset = variable_token .col_offset ,
348
+ end_line_no = variable_token .lineno ,
349
+ end_col_offset = variable_token .end_col_offset ,
340
350
source = self .source ,
341
351
)
342
352
@@ -749,14 +759,17 @@ async def yield_variables(
749
759
skip_commandline_variables : bool = False ,
750
760
) -> AsyncGenerator [Tuple [VariableMatcher , VariableDefinition ], None ]:
751
761
from robot .parsing .model .blocks import Keyword , TestCase
762
+ from robot .parsing .model .statements import Arguments
752
763
753
764
# await self.ensure_initialized()
754
765
755
766
yielded : Dict [VariableMatcher , VariableDefinition ] = {}
756
767
757
768
async for var in async_chain (
758
769
* [
759
- await BlockVariableVisitor ().get (self .source , n , position )
770
+ await BlockVariableVisitor (
771
+ self .source , position , isinstance (nodes [- 1 ], Arguments ) if nodes else False
772
+ ).get (n )
760
773
for n in nodes or []
761
774
if isinstance (n , (Keyword , TestCase ))
762
775
],
0 commit comments