Skip to content

Commit ff5d9ed

Browse files
committed
chore: some optimizations on *imports changed locking
1 parent c670989 commit ff5d9ed

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

robotcode/language_server/robotframework/diagnostics/imports_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ async def _get_libdoc(name: str, args: Tuple[Any, ...], working_dir: str, base_d
10851085
return await entry.get_libdoc()
10861086

10871087
@_logger.call
1088-
async def get_libdoc_from_model(
1088+
def get_libdoc_from_model(
10891089
self,
10901090
model: ast.AST,
10911091
source: str,

robotcode/language_server/robotframework/diagnostics/namespace.py

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -635,30 +635,51 @@ async def imports_changed(self, sender: Any, uri: DocumentUri) -> None: # NOSON
635635

636636
@_logger.call
637637
async def libraries_changed(self, sender: Any, libraries: List[LibraryDoc]) -> None:
638-
for p in libraries:
639-
if any(e for e in self._libraries.values() if e.library_doc == p):
640-
if self.document is not None:
641-
self.document.set_data(Namespace.DataEntry, None)
642-
await self.invalidate()
643-
break
638+
invalidate = False
639+
640+
async with self._initialize_lock, self._library_doc_lock, self._analyze_lock:
641+
for p in libraries:
642+
if any(e for e in self._libraries.values() if e.library_doc == p):
643+
invalidate = True
644+
break
645+
646+
if invalidate:
647+
if self.document is not None:
648+
self.document.set_data(Namespace.DataEntry, None)
649+
650+
await self.invalidate()
644651

645652
@_logger.call
646653
async def resources_changed(self, sender: Any, resources: List[LibraryDoc]) -> None:
647-
for p in resources:
648-
if any(e for e in self._resources.values() if e.library_doc.source == p.source):
649-
if self.document is not None:
650-
self.document.set_data(Namespace.DataEntry, None)
651-
await self.invalidate()
652-
break
654+
invalidate = False
655+
656+
async with self._initialize_lock, self._library_doc_lock, self._analyze_lock:
657+
for p in resources:
658+
if any(e for e in self._resources.values() if e.library_doc.source == p.source):
659+
invalidate = True
660+
break
661+
662+
if invalidate:
663+
if self.document is not None:
664+
self.document.set_data(Namespace.DataEntry, None)
665+
666+
await self.invalidate()
653667

654668
@_logger.call
655669
async def variables_changed(self, sender: Any, variables: List[LibraryDoc]) -> None:
656-
for p in variables:
657-
if any(e for e in self._variables.values() if e.library_doc.source == p.source):
658-
if self.document is not None:
659-
self.document.set_data(Namespace.DataEntry, None)
660-
await self.invalidate()
661-
break
670+
invalidate = False
671+
672+
async with self._initialize_lock, self._library_doc_lock, self._analyze_lock:
673+
for p in variables:
674+
if any(e for e in self._variables.values() if e.library_doc.source == p.source):
675+
invalidate = True
676+
break
677+
678+
if invalidate:
679+
if self.document is not None:
680+
self.document.set_data(Namespace.DataEntry, None)
681+
682+
await self.invalidate()
662683

663684
async def is_initialized(self) -> bool:
664685
async with self._initialize_lock:
@@ -753,7 +774,7 @@ async def get_imported_variables(self) -> OrderedDict[str, VariablesEntry]:
753774
async def get_library_doc(self) -> LibraryDoc:
754775
async with self._library_doc_lock:
755776
if self._library_doc is None:
756-
self._library_doc = await self.imports_manager.get_libdoc_from_model(
777+
self._library_doc = self.imports_manager.get_libdoc_from_model(
757778
self.model,
758779
self.source,
759780
model_type="RESOURCE",

robotcode/utils/async_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def aaa(fut: asyncio.Future[Any]) -> None:
465465
warnings.warn(f"Lock {self} takes to long {threading.current_thread()}\n, try to cancel...")
466466
fut.cancel()
467467

468-
h = fut.get_loop().call_later(120, aaa, fut)
468+
h = fut.get_loop().call_later(60, aaa, fut)
469469
try:
470470
await fut
471471
finally:

0 commit comments

Comments
 (0)