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

Method open

src/index.ts:475–518  ·  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

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