Skip to content

Commit 9989edf

Browse files
committed
fix: speedup loading and analysing tests
Instead of waiting for diagnostics load and analyse documents one by one, load first the documents and then start analysing and discovering in different tasks/threads
1 parent 2f8579a commit 9989edf

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

robotcode/language_server/robotframework/diagnostics/imports_manager.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,19 @@ async def is_valid(self) -> bool:
152152
class _LibrariesEntry(_ImportEntry):
153153
def __init__(
154154
self,
155+
parent: ImportsManager,
155156
name: str,
156157
args: Tuple[Any, ...],
157-
parent: ImportsManager,
158-
get_libdoc_coroutine: Callable[[], Coroutine[Any, Any, LibraryDoc]],
158+
working_dir: str,
159+
base_dir: str,
160+
get_libdoc_coroutine: Callable[[str, Tuple[Any, ...], str, str], Coroutine[Any, Any, LibraryDoc]],
159161
ignore_reference: bool = False,
160162
) -> None:
161163
super().__init__(parent)
162164
self.name = name
163165
self.args = args
166+
self.working_dir = working_dir
167+
self.base_dir = base_dir
164168
self._get_libdoc_coroutine = get_libdoc_coroutine
165169
self._lib_doc: Optional[LibraryDoc] = None
166170
self.ignore_reference = ignore_reference
@@ -211,7 +215,7 @@ async def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileCha
211215
return None
212216

213217
async def _update(self) -> None:
214-
self._lib_doc = await self._get_libdoc_coroutine()
218+
self._lib_doc = await self._get_libdoc_coroutine(self.name, self.args, self.working_dir, self.base_dir)
215219

216220
source_or_origin = (
217221
self._lib_doc.source
@@ -893,7 +897,7 @@ async def get_libdoc_for_library_import(
893897
variables,
894898
)
895899

896-
async def _get_libdoc() -> LibraryDoc:
900+
async def _get_libdoc(name: str, args: Tuple[Any, ...], working_dir: str, base_dir: str) -> LibraryDoc:
897901

898902
meta, source = await self.get_library_meta(
899903
name,
@@ -926,7 +930,7 @@ async def _get_libdoc() -> LibraryDoc:
926930
get_library_doc,
927931
name,
928932
args,
929-
str(self.folder.to_path()),
933+
working_dir,
930934
base_dir,
931935
self.config.robot.variables if self.config.robot is not None else None,
932936
variables,
@@ -960,7 +964,13 @@ async def _get_libdoc() -> LibraryDoc:
960964
async with self._libaries_lock:
961965
if entry_key not in self._libaries:
962966
self._libaries[entry_key] = _LibrariesEntry(
963-
name, args, self, _get_libdoc, ignore_reference=sentinel is None
967+
self,
968+
name,
969+
args,
970+
str(self.folder.to_path()),
971+
base_dir,
972+
_get_libdoc,
973+
ignore_reference=sentinel is None,
964974
)
965975

966976
entry = self._libaries[entry_key]

robotcode/language_server/robotframework/parts/discovering.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ def generate(suite: TestSuite) -> TestItem:
217217
else None,
218218
)
219219

220-
await self.parent.diagnostics.ensure_workspace_loaded()
220+
# await self.parent.diagnostics.ensure_workspace_loaded()
221+
await self.parent.robot_workspace.documents_loaded.wait()
221222

222223
workspace_path = Uri(workspace_folder).to_path()
223224
with LOGGER.cache_only:

robotcode/language_server/robotframework/parts/robot_workspace.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, parent: RobotLanguageServerProtocol) -> None:
4040
self.parent.diagnostics.on_get_diagnostics_mode.add(self.on_get_diagnostics_mode)
4141
self.parent.diagnostics.on_get_analysis_progress_mode.add(self.on_get_analysis_progress_mode)
4242
self.parent.on_initialized.add(self.on_initialized)
43-
self.workspace_loaded = Event()
43+
self.documents_loaded = Event()
4444

4545
async def on_initialized(self, sender: Any) -> None:
4646
await self.parent.workspace.add_file_watcher(
@@ -100,6 +100,22 @@ async def _load_workspace_documents(self, sender: Any) -> List[WorkspaceDocument
100100
async with self.parent.window.progress(
101101
"Load workspace", cancellable=True, current=0, max=len(files), start=False
102102
) as progress:
103+
for i, f in enumerate(files):
104+
await self.parent.documents.get_or_open_document(f, "robotframework")
105+
106+
if config.analysis.progress_mode != AnalysisProgressMode.OFF:
107+
name = f.relative_to(folder.uri.to_path())
108+
109+
progress.begin()
110+
progress.report(
111+
f"Load {str(name)}"
112+
if config.analysis.progress_mode == AnalysisProgressMode.DETAILED
113+
else None,
114+
current=i,
115+
)
116+
117+
self.documents_loaded.set()
118+
103119
for i, f in enumerate(files):
104120
try:
105121
if progress.is_canceled:
@@ -111,7 +127,7 @@ async def _load_workspace_documents(self, sender: Any) -> List[WorkspaceDocument
111127
if config.analysis.progress_mode != AnalysisProgressMode.OFF:
112128
progress.begin()
113129
progress.report(
114-
f"Load {str(name)}"
130+
f"Initialize {str(name)}"
115131
if config.analysis.progress_mode == AnalysisProgressMode.DETAILED
116132
else None,
117133
current=i,
@@ -140,8 +156,6 @@ async def _load_workspace_documents(self, sender: Any) -> List[WorkspaceDocument
140156
except BaseException as e:
141157
self._logger.exception(e)
142158

143-
self.workspace_loaded.set()
144-
145159
if canceled:
146160
return []
147161

0 commit comments

Comments
 (0)