1
1
import ast
2
2
from concurrent .futures import CancelledError
3
- from typing import TYPE_CHECKING , Any , Callable , List , Optional , Type , cast
3
+ from typing import TYPE_CHECKING , Any , Callable , Iterable , List , Optional , Type , cast
4
4
5
5
from robot .parsing .lexer .tokens import Token as RobotToken
6
6
from robot .parsing .model import statements
@@ -150,7 +150,7 @@ def _find_references_in_workspace(
150
150
self ,
151
151
document : TextDocument ,
152
152
stop_at_first : bool ,
153
- func : Callable [..., List [Location ]],
153
+ func : Callable [..., Iterable [Location ]],
154
154
* args : Any ,
155
155
** kwargs : Any ,
156
156
) -> List [Location ]:
@@ -249,73 +249,44 @@ def find_variable_references_in_file(
249
249
doc : TextDocument ,
250
250
variable : VariableDefinition ,
251
251
include_declaration : bool = True ,
252
- ) -> List [Location ]:
252
+ ) -> Iterable [Location ]:
253
253
try :
254
254
namespace = self .parent .documents_cache .get_namespace (doc )
255
255
256
- if (
257
- variable .source
258
- and variable .source != str (doc .uri .to_path ())
259
- and not any (e for e in (namespace .get_resources ()).values () if e .library_doc .source == variable .source )
260
- and not any (
261
- e for e in namespace .get_variables_imports ().values () if e .library_doc .source == variable .source
262
- )
263
- and not any (e for e in namespace .get_command_line_variables () if e .source == variable .source )
264
- ):
265
- return []
266
-
267
- result = set ()
268
- if include_declaration and variable .source :
269
- result .add (Location (str (Uri .from_path (variable .source )), variable .name_range ))
270
-
271
256
refs = namespace .get_variable_references ()
272
257
if variable in refs :
273
- result |= refs [variable ]
258
+ if include_declaration and variable .source == namespace .source :
259
+ yield Location (str (Uri .from_path (variable .source )), variable .name_range )
260
+
261
+ yield from refs [variable ]
274
262
275
- return list (result )
276
263
except (SystemExit , KeyboardInterrupt , CancelledError ):
277
264
raise
278
265
except BaseException as e :
279
266
self ._logger .exception (e )
280
267
281
- return []
282
-
283
268
@_logger .call
284
269
def find_keyword_references_in_file (
285
270
self ,
286
271
doc : TextDocument ,
287
272
kw_doc : KeywordDoc ,
288
- lib_doc : Optional [LibraryDoc ] = None ,
289
273
include_declaration : bool = True ,
290
- ) -> List [Location ]:
274
+ ) -> Iterable [Location ]:
291
275
try :
292
276
namespace = self .parent .documents_cache .get_namespace (doc )
293
277
294
- if (
295
- lib_doc is not None
296
- and lib_doc .source is not None
297
- and lib_doc .source != str (doc .uri .to_path ())
298
- and lib_doc not in (e .library_doc for e in (namespace .get_libraries ()).values ())
299
- and lib_doc not in (e .library_doc for e in (namespace .get_resources ()).values ())
300
- ):
301
- return []
302
-
303
- result = set ()
304
- if include_declaration and kw_doc .source :
305
- result .add (Location (str (Uri .from_path (kw_doc .source )), kw_doc .range ))
306
-
307
278
refs = namespace .get_keyword_references ()
308
279
if kw_doc in refs :
309
- result |= refs [kw_doc ]
280
+ if include_declaration and kw_doc .source == namespace .source :
281
+ yield Location (str (Uri .from_path (kw_doc .source )), kw_doc .range )
282
+
283
+ yield from refs [kw_doc ]
310
284
311
- return list (result )
312
285
except (SystemExit , KeyboardInterrupt , CancelledError ):
313
286
raise
314
287
except BaseException as e :
315
288
self ._logger .exception (e )
316
289
317
- return []
318
-
319
290
def has_cached_keyword_references (
320
291
self ,
321
292
document : TextDocument ,
@@ -346,28 +317,6 @@ def _find_keyword_references(
346
317
include_declaration : bool = True ,
347
318
stop_at_first : bool = False ,
348
319
) -> List [Location ]:
349
- namespace = self .parent .documents_cache .get_namespace (document )
350
-
351
- lib_doc = (
352
- next (
353
- (
354
- e .library_doc
355
- for e in (namespace .get_libraries ()).values ()
356
- if kw_doc in e .library_doc .keywords .values ()
357
- ),
358
- None ,
359
- )
360
- or next (
361
- (
362
- e .library_doc
363
- for e in (namespace .get_resources ()).values ()
364
- if kw_doc in e .library_doc .keywords .values ()
365
- ),
366
- None ,
367
- )
368
- or namespace .get_library_doc ()
369
- )
370
-
371
320
result = []
372
321
373
322
if include_declaration and kw_doc .source :
@@ -379,7 +328,6 @@ def _find_keyword_references(
379
328
stop_at_first ,
380
329
self .find_keyword_references_in_file ,
381
330
kw_doc ,
382
- lib_doc ,
383
331
False ,
384
332
)
385
333
)
0 commit comments