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

Method open

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

298 * @returns A CodeGraph instance
299 */
300 static async open(projectRoot: string, options: OpenOptions = {}): Promise<CodeGraph> {
301 await initGrammars();
302 const resolvedRoot = path.resolve(projectRoot);
303
304 // Check if initialized
305 if (!isInitialized(resolvedRoot)) {
306 throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`);
307 }
308
309 // Validate directory structure
310 const validation = validateDirectory(resolvedRoot);
311 if (!validation.valid) {
312 throw new Error(`Invalid CodeGraph directory: ${validation.errors.join(', ')}`);
313 }
314
315 // Open database
316 const dbPath = getDatabasePath(resolvedRoot);
317 const db = DatabaseConnection.open(dbPath);
318 const queries = new QueryBuilder(db.getDb());
319
320 const instance = new CodeGraph(db, queries, resolvedRoot);
321
322 // Sync if requested
323 if (options.sync) {
324 await instance.sync();
325 }
326
327 return instance;
328 }
329
330 /**
331 * Rebuild the project's database from scratch and return a fresh, empty

Callers 2

reopenIfReplacedMethod · 0.45
openSyncMethod · 0.45

Calls 8

syncMethod · 0.95
initGrammarsFunction · 0.90
isInitializedFunction · 0.90
validateDirectoryFunction · 0.90
getDatabasePathFunction · 0.90
resolveMethod · 0.80
getDbMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected