@@ -149,12 +149,12 @@ def __hash__(self) -> int:
149
149
def range (self ) -> Range :
150
150
return Range (
151
151
start = Position (
152
- line = self .name_token . lineno - 1 if self . name_token is not None else self . line_no - 1 ,
153
- character = self .name_token . col_offset if self . name_token is not None else self . col_offset ,
152
+ line = self .line_no - 1 ,
153
+ character = self .col_offset ,
154
154
),
155
155
end = Position (
156
- line = self .name_token . lineno - 1 if self . name_token is not None else self . end_line_no - 1 ,
157
- character = self .name_token . end_col_offset if self . name_token is not None else self . end_col_offset ,
156
+ line = self .end_line_no - 1 ,
157
+ character = self .end_col_offset ,
158
158
),
159
159
)
160
160
@@ -212,39 +212,77 @@ async def visit_Variable(self, node: ast.AST) -> None: # noqa: N802
212
212
)
213
213
214
214
215
- class ArgumentsVisitor (AsyncVisitor ):
215
+ class BlockVariableVisitor (AsyncVisitor ):
216
216
async def get (self , source : str , model : ast .AST ) -> List [VariableDefinition ]:
217
217
self ._results : List [VariableDefinition ] = []
218
218
self .source = source
219
219
await self .visit (model )
220
220
return self ._results
221
221
222
- async def visit_Section (self , node : ast .AST ) -> None : # noqa: N802
223
- from robot .parsing .model .blocks import VariableSection
224
-
225
- if isinstance (node , VariableSection ):
226
- await self .generic_visit (node )
227
-
228
222
async def visit_Arguments (self , node : ast .AST ) -> None : # noqa: N802
223
+ from robot .errors import VariableError
229
224
from robot .parsing .lexer .tokens import Token as RobotToken
230
225
from robot .parsing .model .statements import Arguments
231
226
from robot .variables .search import is_variable
232
227
233
228
n = cast (Arguments , node )
234
229
arguments = n .get_tokens (RobotToken .ARGUMENT )
235
230
for argument in (cast (RobotToken , e ) for e in arguments ):
236
- if is_variable (argument .value ):
231
+ try :
232
+ if is_variable (argument .value ):
233
+ self ._results .append (
234
+ ArgumentDefinition (
235
+ name = argument .value ,
236
+ name_token = argument ,
237
+ line_no = node .lineno ,
238
+ col_offset = node .col_offset ,
239
+ end_line_no = node .end_lineno
240
+ if node .end_lineno is not None
241
+ else argument .lineno
242
+ if argument .lineno is not None
243
+ else - 1 ,
244
+ end_col_offset = node .end_col_offset
245
+ if node .end_col_offset is not None
246
+ else argument .end_col_offset
247
+ if argument .end_col_offset is not None
248
+ else - 1 ,
249
+ source = self .source ,
250
+ )
251
+ )
252
+ except VariableError :
253
+ pass
254
+
255
+ async def visit_KeywordCall (self , node : ast .AST ) -> None : # noqa: N802
256
+ from robot .errors import VariableError
257
+ from robot .parsing .lexer .tokens import Token as RobotToken
258
+ from robot .parsing .model .statements import KeywordCall
259
+ from robot .variables .search import contains_variable
260
+
261
+ try :
262
+ n = cast (KeywordCall , node )
263
+ assign_token = n .get_token (RobotToken .ASSIGN )
264
+ if assign_token is not None and assign_token .value and contains_variable (assign_token .value ):
237
265
self ._results .append (
238
- ArgumentDefinition (
239
- name = argument .value ,
240
- name_token = argument ,
241
- line_no = argument .lineno ,
242
- col_offset = argument .col_offset ,
243
- end_line_no = argument .lineno if argument .lineno is not None else - 1 ,
244
- end_col_offset = argument .end_col_offset if argument .end_col_offset is not None else - 1 ,
266
+ VariableDefinition (
267
+ name = assign_token .value ,
268
+ name_token = assign_token ,
269
+ line_no = node .lineno ,
270
+ col_offset = node .col_offset ,
271
+ end_line_no = node .end_lineno
272
+ if node .end_lineno is not None
273
+ else assign_token .lineno
274
+ if assign_token .lineno is not None
275
+ else - 1 ,
276
+ end_col_offset = node .end_col_offset
277
+ if node .end_col_offset is not None
278
+ else assign_token .end_col_offset
279
+ if assign_token .end_col_offset is not None
280
+ else - 1 ,
245
281
source = self .source ,
246
282
)
247
283
)
284
+ except VariableError :
285
+ pass
248
286
249
287
250
288
class ImportVisitor (AsyncVisitor ):
@@ -851,14 +889,18 @@ def get_builtin_variables(cls) -> List[BuiltInVariableDefinition]:
851
889
return cls ._builtin_variables
852
890
853
891
async def get_variables (self , nodes : Optional [List [ast .AST ]] = None ) -> Dict [VariableMatcher , VariableDefinition ]:
854
- from robot .parsing .model .blocks import Keyword
892
+ from robot .parsing .model .blocks import Keyword , TestCase
855
893
856
894
await self ._ensure_initialized ()
857
895
858
896
result : Dict [VariableMatcher , VariableDefinition ] = {}
859
897
860
898
async for var in async_chain (
861
- * [await ArgumentsVisitor ().get (self .source , n ) for n in nodes or [] if isinstance (n , Keyword )],
899
+ * [
900
+ await BlockVariableVisitor ().get (self .source , n )
901
+ for n in nodes or []
902
+ if isinstance (n , (Keyword , TestCase ))
903
+ ],
862
904
(e for e in await self .get_own_variables ()),
863
905
* (e .variables for e in self ._resources .values ()),
864
906
(e for e in self .get_builtin_variables ()),
0 commit comments