MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / open

Method open

src/index.ts:471–514  ·  view source on GitHub ↗

* Open an existing CodeGraph project * * @param projectRoot - Path to the project root directory * @param options - Open options * @returns A CodeGraph instance

(projectRoot: string, options: OpenOptions = {})

Source from the content-addressed store, hash-verified

469 * @returns A CodeGraph instance
470 */
471 static async open(projectRoot: string, options: OpenOptions = {}): Promise<CodeGraph> {
472 await initGrammars();
473 const resolvedRoot = path.resolve(projectRoot);
474
475 // Check if initialized
476 if (!isInitialized(resolvedRoot)) {
477 throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`);
478 }
479
480 // Validate directory structure
481 const validation = validateDirectory(resolvedRoot);
482 if (!validation.valid) {
483 throw new Error(`Invalid CodeGraph directory: ${validation.errors.join(', ')}`);
484 }
485
486 // Open database. The secondary indexes an interrupted bulk load dropped are
487 // rebuilt off this thread, and finished before the instance is returned
488 // (#1887): rebuilt in line on a large index, they blocked the thread longer
489 // than the liveness watchdog allows, and every restart was killed the same
490 // way.
491 const dbPath = getDatabasePath(resolvedRoot);
492 const db = DatabaseConnection.open(dbPath, { readOnly: options.readOnly, deferIndexRecovery: true });
493 try {
494 await db.recoverIndexesOffThread();
495 } catch (err) {
496 db.close();
497 throw err;
498 }
499 const queries = new QueryBuilder(db.getDb());
500
501 const instance = new CodeGraph(db, queries, resolvedRoot);
502
503 // Sync if requested
504 if (options.sync && !options.readOnly) {
505 try {
506 await instance.sync();
507 } catch (err) {
508 instance.destroy();
509 throw err;
510 }
511 }
512
513 return instance;
514 }
515
516 /**
517 * Rebuild the project's database from scratch and return a fresh, empty

Callers

nothing calls this directly

Calls 12

syncMethod · 0.95
destroyMethod · 0.95
initGrammarsFunction · 0.90
isInitializedFunction · 0.90
validateDirectoryFunction · 0.90
getDatabasePathFunction · 0.90
getDbMethod · 0.80
resolveMethod · 0.65
openMethod · 0.65
closeMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected