|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import asyncio |
| 4 | +import time |
4 | 5 | from typing import TYPE_CHECKING, Any, List, Optional |
5 | 6 |
|
6 | 7 | from ....utils.async_tools import Event, threaded |
@@ -74,73 +75,77 @@ async def on_get_analysis_progress_mode(self, sender: Any, uri: Uri) -> Optional |
74 | 75 |
|
75 | 76 | @threaded() |
76 | 77 | async def _load_workspace_documents(self, sender: Any) -> List[WorkspaceDocumentsResult]: |
| 78 | + start = time.monotonic() |
| 79 | + try: |
| 80 | + |
| 81 | + result: List[WorkspaceDocumentsResult] = [] |
| 82 | + |
| 83 | + for folder in self.parent.workspace.workspace_folders: |
| 84 | + config = await self.parent.workspace.get_configuration(RobotCodeConfig, folder.uri) |
| 85 | + |
| 86 | + async with self.parent.window.progress("Collect sources", cancellable=False): |
| 87 | + files = [ |
| 88 | + f |
| 89 | + for f in iter_files( |
| 90 | + folder.uri.to_path(), |
| 91 | + f"**/*.{{{ROBOT_FILE_EXTENSION[1:]},{RESOURCE_FILE_EXTENSION[1:]}}}", |
| 92 | + ignore_patterns=config.workspace.exclude_patterns or [], |
| 93 | + absolute=True, |
| 94 | + ) |
| 95 | + ] |
| 96 | + |
| 97 | + canceled = False |
| 98 | + async with self.parent.window.progress( |
| 99 | + "Load workspace", cancellable=True, current=0, max=len(files), start=False |
| 100 | + ) as progress: |
| 101 | + for i, f in enumerate(files): |
| 102 | + try: |
| 103 | + if progress.is_canceled: |
| 104 | + canceled = True |
| 105 | + break |
| 106 | + |
| 107 | + name = f.relative_to(folder.uri.to_path()) |
| 108 | + |
| 109 | + if config.analysis.progress_mode != AnalysisProgressMode.OFF: |
| 110 | + progress.begin() |
| 111 | + progress.report( |
| 112 | + f"Load {str(name)}" |
| 113 | + if config.analysis.progress_mode == AnalysisProgressMode.DETAILED |
| 114 | + else None, |
| 115 | + current=i, |
| 116 | + ) |
| 117 | + |
| 118 | + if not f.exists(): |
| 119 | + continue |
| 120 | + |
| 121 | + document = await self.parent.documents.get_or_open_document(f, "robotframework") |
77 | 122 |
|
78 | | - result: List[WorkspaceDocumentsResult] = [] |
79 | | - |
80 | | - for folder in self.parent.workspace.workspace_folders: |
81 | | - config = await self.parent.workspace.get_configuration(RobotCodeConfig, folder.uri) |
82 | | - |
83 | | - async with self.parent.window.progress("Collect sources", cancellable=False): |
84 | | - files = [ |
85 | | - f |
86 | | - for f in iter_files( |
87 | | - folder.uri.to_path(), |
88 | | - f"**/*.{{{ROBOT_FILE_EXTENSION[1:]},{RESOURCE_FILE_EXTENSION[1:]}}}", |
89 | | - ignore_patterns=config.workspace.exclude_patterns or [], |
90 | | - absolute=True, |
91 | | - ) |
92 | | - ] |
93 | | - |
94 | | - canceled = False |
95 | | - async with self.parent.window.progress( |
96 | | - "Load workspace", cancellable=True, current=0, max=len(files), start=False |
97 | | - ) as progress: |
98 | | - for i, f in enumerate(files): |
99 | | - try: |
100 | | - if progress.is_canceled: |
101 | | - canceled = True |
102 | | - break |
103 | | - |
104 | | - name = f.relative_to(folder.uri.to_path()) |
105 | | - |
106 | | - if config.analysis.progress_mode != AnalysisProgressMode.OFF: |
107 | | - progress.begin() |
108 | | - progress.report( |
109 | | - f"Load {str(name)}" |
110 | | - if config.analysis.progress_mode == AnalysisProgressMode.DETAILED |
111 | | - else None, |
112 | | - current=i, |
113 | | - ) |
114 | | - |
115 | | - if not f.exists(): |
116 | | - continue |
117 | | - |
118 | | - document = await self.parent.documents.get_or_open_document(f, "robotframework") |
119 | | - |
120 | | - if not document.opened_in_editor: |
121 | | - await (await self.parent.documents_cache.get_namespace(document)).ensure_initialized() |
122 | | - |
123 | | - if config.analysis.diagnostic_mode == DiagnosticsMode.WORKSPACE: |
124 | | - result.append( |
125 | | - WorkspaceDocumentsResult( |
126 | | - str(name) |
127 | | - if config.analysis.progress_mode == AnalysisProgressMode.DETAILED |
128 | | - else None, |
129 | | - document, |
| 123 | + if not document.opened_in_editor: |
| 124 | + await (await self.parent.documents_cache.get_namespace(document)).ensure_initialized() |
| 125 | + |
| 126 | + if config.analysis.diagnostic_mode == DiagnosticsMode.WORKSPACE: |
| 127 | + result.append( |
| 128 | + WorkspaceDocumentsResult( |
| 129 | + str(name) |
| 130 | + if config.analysis.progress_mode == AnalysisProgressMode.DETAILED |
| 131 | + else None, |
| 132 | + document, |
| 133 | + ) |
130 | 134 | ) |
131 | | - ) |
132 | 135 |
|
133 | | - except (SystemExit, KeyboardInterrupt, asyncio.CancelledError): |
134 | | - raise |
135 | | - except BaseException as e: |
136 | | - self._logger.exception(e) |
| 136 | + except (SystemExit, KeyboardInterrupt, asyncio.CancelledError): |
| 137 | + raise |
| 138 | + except BaseException as e: |
| 139 | + self._logger.exception(e) |
137 | 140 |
|
138 | | - self.workspace_loaded.set() |
| 141 | + self.workspace_loaded.set() |
139 | 142 |
|
140 | | - if canceled: |
141 | | - return [] |
| 143 | + if canceled: |
| 144 | + return [] |
142 | 145 |
|
143 | | - if config.analysis.max_project_file_count > 0 and len(files) > config.analysis.max_project_file_count: |
144 | | - result = result[: config.analysis.max_project_file_count] |
| 146 | + if config.analysis.max_project_file_count > 0 and len(files) > config.analysis.max_project_file_count: |
| 147 | + result = result[: config.analysis.max_project_file_count] |
145 | 148 |
|
146 | | - return result |
| 149 | + return result |
| 150 | + finally: |
| 151 | + self._logger.debug(f"Workspace loaded in {time.monotonic() - start}s") |
0 commit comments