@@ -589,8 +589,9 @@ def __init__(
589
589
self ._keyword_references : Dict [KeywordDoc , Set [Location ]] = {}
590
590
self ._variable_references : Dict [VariableDefinition , Set [Location ]] = {}
591
591
592
+ self ._imported_keywords : Optional [List [KeywordDoc ]] = None
593
+ self ._imported_keywords_lock = Lock ()
592
594
self ._keywords : Optional [List [KeywordDoc ]] = None
593
-
594
595
self ._keywords_lock = Lock ()
595
596
596
597
# TODO: how to get the search order from model
@@ -673,6 +674,7 @@ async def _invalidate(self) -> None:
673
674
self ._imports = None
674
675
self ._import_entries = OrderedDict ()
675
676
self ._own_variables = None
677
+ self ._imported_keywords = None
676
678
self ._keywords = None
677
679
self ._library_doc = None
678
680
self ._analyzed = False
@@ -766,6 +768,7 @@ class DataEntry(NamedTuple):
766
768
variables : OrderedDict [str , VariablesEntry ] = OrderedDict ()
767
769
diagnostics : List [Diagnostic ] = []
768
770
import_entries : OrderedDict [Import , LibraryEntry ] = OrderedDict ()
771
+ imported_keywords : Optional [List [KeywordDoc ]] = None
769
772
770
773
@_logger .call (condition = lambda self : not self ._initialized )
771
774
async def ensure_initialized (self ) -> bool :
@@ -812,8 +815,10 @@ async def ensure_initialized(self) -> bool:
812
815
self ._variables = data_entry .variables .copy ()
813
816
self ._diagnostics = data_entry .diagnostics .copy ()
814
817
self ._import_entries = data_entry .import_entries .copy ()
818
+ self ._imported_keywords = (
819
+ data_entry .imported_keywords .copy () if data_entry .imported_keywords else None
820
+ )
815
821
else :
816
-
817
822
variables = await self .get_resolvable_variables ()
818
823
819
824
await self ._import_default_libraries (variables )
@@ -830,6 +835,7 @@ async def ensure_initialized(self) -> bool:
830
835
self ._variables .copy (),
831
836
self ._diagnostics .copy (),
832
837
self ._import_entries .copy (),
838
+ self ._imported_keywords .copy () if self ._imported_keywords else None ,
833
839
),
834
840
)
835
841
@@ -1475,16 +1481,27 @@ async def get_imported_variables_libdoc(self, name: str, args: Tuple[str, ...] =
1475
1481
None ,
1476
1482
)
1477
1483
1484
+ async def get_imported_keywords (self ) -> List [KeywordDoc ]:
1485
+ async with self ._imported_keywords_lock :
1486
+ if self ._imported_keywords is None :
1487
+ self ._imported_keywords = list (
1488
+ itertools .chain (
1489
+ * (e .library_doc .keywords for e in self ._libraries .values ()),
1490
+ * (e .library_doc .keywords for e in self ._resources .values ()),
1491
+ )
1492
+ )
1493
+
1494
+ return self ._imported_keywords
1495
+
1478
1496
@_logger .call
1479
1497
async def iter_all_keywords (self ) -> AsyncGenerator [KeywordDoc , None ]:
1480
1498
import itertools
1481
1499
1482
1500
libdoc = await self .get_library_doc ()
1483
1501
1484
1502
for doc in itertools .chain (
1485
- * (e .library_doc .keywords .values () for e in self ._libraries .values ()),
1486
- * (e .library_doc .keywords .values () for e in self ._resources .values ()),
1487
- libdoc .keywords .values () if libdoc is not None else [],
1503
+ await self .get_imported_keywords (),
1504
+ libdoc .keywords if libdoc is not None else [],
1488
1505
):
1489
1506
yield doc
1490
1507
@@ -1504,10 +1521,13 @@ async def get_keywords(self) -> List[KeywordDoc]:
1504
1521
1505
1522
async for doc in self .iter_all_keywords ():
1506
1523
i += 1
1507
- result [KeywordMatcher ( doc .name ) ] = doc
1524
+ result [doc .matcher ] = doc
1508
1525
1509
1526
self ._keywords = list (result .values ())
1510
- finally :
1527
+ except BaseException :
1528
+ self ._logger .debug ("Canceled collecting keywords " )
1529
+ raise
1530
+ else :
1511
1531
self ._logger .debug (
1512
1532
lambda : f"end collecting { len (self ._keywords ) if self ._keywords else 0 } "
1513
1533
f" keywords in { time .monotonic ()- current_time } s analyze { i } keywords"
0 commit comments