@@ -141,12 +141,19 @@ async def visit_Variable(self, node: ast.AST) -> None: # noqa: N802
141141
142142
143143class 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+
145147 self .source = source
146148 self .position = position
149+ self .in_args = in_args
147150
148151 self ._results : Dict [str , VariableDefinition ] = {}
149152
153+ async def get (self , model : ast .AST ) -> List [VariableDefinition ]:
154+
155+ self ._results = {}
156+
150157 await self .visit (model )
151158
152159 return list (self ._results .values ())
@@ -178,10 +185,10 @@ async def visit_KeywordName(self, node: ast.AST) -> None: # noqa: N802
178185 self ._results [name ] = ArgumentDefinition (
179186 name = name ,
180187 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 ,
185192 source = self .source ,
186193 )
187194
@@ -212,13 +219,16 @@ async def visit_Arguments(self, node: ast.AST) -> None: # noqa: N802
212219 argument = self .get_variable_token (argument_token )
213220
214221 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+
215225 self ._results [argument .value ] = ArgumentDefinition (
216226 name = argument .value ,
217227 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 ,
222232 source = self .source ,
223233 )
224234
@@ -241,10 +251,10 @@ async def visit_ExceptHeader(self, node: ast.AST) -> None: # noqa: N802
241251 self ._results [variable .value ] = LocalVariableDefinition (
242252 name = variable .value ,
243253 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 ,
248258 source = self .source ,
249259 )
250260
@@ -276,10 +286,10 @@ async def visit_KeywordCall(self, node: ast.AST) -> None: # noqa: N802
276286 self ._results [variable_token .value ] = LocalVariableDefinition (
277287 name = variable_token .value ,
278288 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 ,
283293 source = self .source ,
284294 )
285295
@@ -311,10 +321,10 @@ async def visit_InlineIfHeader(self, node: ast.AST) -> None: # noqa: N802
311321 self ._results [variable_token .value ] = LocalVariableDefinition (
312322 name = variable_token .value ,
313323 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 ,
318328 source = self .source ,
319329 )
320330
@@ -333,10 +343,10 @@ async def visit_ForHeader(self, node: ast.AST) -> None: # noqa: N802
333343 self ._results [variable_token .value ] = LocalVariableDefinition (
334344 name = variable_token .value ,
335345 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 ,
340350 source = self .source ,
341351 )
342352
@@ -749,14 +759,17 @@ async def yield_variables(
749759 skip_commandline_variables : bool = False ,
750760 ) -> AsyncGenerator [Tuple [VariableMatcher , VariableDefinition ], None ]:
751761 from robot .parsing .model .blocks import Keyword , TestCase
762+ from robot .parsing .model .statements import Arguments
752763
753764 # await self.ensure_initialized()
754765
755766 yielded : Dict [VariableMatcher , VariableDefinition ] = {}
756767
757768 async for var in async_chain (
758769 * [
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 )
760773 for n in nodes or []
761774 if isinstance (n , (Keyword , TestCase ))
762775 ],
0 commit comments