Request indexing with streaming progress. Blocks until complete.
(
project_root: str,
on_progress: Callable[[IndexingProgress], None] | None = None,
on_waiting: Callable[[], None] | None = None,
)
| 255 | |
| 256 | |
| 257 | def index( |
| 258 | project_root: str, |
| 259 | on_progress: Callable[[IndexingProgress], None] | None = None, |
| 260 | on_waiting: Callable[[], None] | None = None, |
| 261 | ) -> IndexResponse: |
| 262 | """Request indexing with streaming progress. Blocks until complete.""" |
| 263 | project_root = normalize_input_path(project_root) |
| 264 | conn = _connect_and_handshake() |
| 265 | try: |
| 266 | conn.send_bytes(encode_request(IndexRequest(project_root=project_root))) |
| 267 | while True: |
| 268 | try: |
| 269 | data = conn.recv_bytes() |
| 270 | except EOFError: |
| 271 | raise RuntimeError("Connection to daemon lost during indexing") |
| 272 | resp = decode_response(data) |
| 273 | if isinstance(resp, ErrorResponse): |
| 274 | raise RuntimeError(f"Daemon error: {resp.message}") |
| 275 | if isinstance(resp, IndexWaitingNotice): |
| 276 | if on_waiting is not None: |
| 277 | on_waiting() |
| 278 | continue |
| 279 | if isinstance(resp, IndexProgressUpdate): |
| 280 | if on_progress is not None: |
| 281 | on_progress(resp.progress) |
| 282 | continue |
| 283 | if isinstance(resp, IndexResponse): |
| 284 | return resp |
| 285 | raise RuntimeError(f"Unexpected response: {type(resp).__name__}") |
| 286 | finally: |
| 287 | conn.close() |
| 288 | |
| 289 | |
| 290 | def search( |
nothing calls this directly
no test coverage detected