MCPcopy Create free account
hub / github.com/cocoindex-io/cocoindex-code / index

Function index

src/cocoindex_code/client.py:257–287  ·  view source on GitHub ↗

Request indexing with streaming progress. Blocks until complete.

(
    project_root: str,
    on_progress: Callable[[IndexingProgress], None] | None = None,
    on_waiting: Callable[[], None] | None = None,
)

Source from the content-addressed store, hash-verified

255
256
257def 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
290def search(

Callers

nothing calls this directly

Calls 6

normalize_input_pathFunction · 0.85
encode_requestFunction · 0.85
IndexRequestClass · 0.85
decode_responseFunction · 0.85
closeMethod · 0.80
_connect_and_handshakeFunction · 0.70

Tested by

no test coverage detected