@@ -779,9 +779,10 @@ class DataEntry(NamedTuple):
779779
780780 @_logger .call (condition = lambda self : not self ._initialized )
781781 async def ensure_initialized (self ) -> bool :
782- async with self . _initialize_lock :
783- imports_changed = False
782+ run_initialize = False
783+ imports_changed = False
784784
785+ async with self ._initialize_lock :
785786 if not self ._initialized :
786787
787788 if self ._in_initialize :
@@ -804,14 +805,7 @@ async def ensure_initialized(self) -> bool:
804805 elif old_imports != imports :
805806 imports_changed = True
806807
807- new_imports = []
808- for e in old_imports :
809- if e in imports :
810- new_imports .append (e )
811- for e in imports :
812- if e not in new_imports :
813- new_imports .append (e )
814- self .document .set_data (Namespace , new_imports )
808+ self .document .set_data (Namespace , imports )
815809 self .document .set_data (Namespace .DataEntry , None )
816810 else :
817811 data_entry = self .document .get_data (Namespace .DataEntry )
@@ -849,6 +843,7 @@ async def ensure_initialized(self) -> bool:
849843 await self ._reset_global_variables ()
850844
851845 self ._initialized = True
846+ run_initialize = True
852847
853848 except BaseException as e :
854849 if not isinstance (e , asyncio .CancelledError ):
@@ -863,7 +858,7 @@ async def ensure_initialized(self) -> bool:
863858 finally :
864859 self ._in_initialize = False
865860
866- if self . _initialized :
861+ if run_initialize :
867862 await self .has_initialized (self )
868863
869864 if imports_changed :
0 commit comments