* 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 = {})
| 333 | * @returns A CodeGraph instance |
| 334 | */ |
| 335 | static async open(projectRoot: string, options: OpenOptions = {}): Promise<CodeGraph> { |
| 336 | await initGrammars(); |
| 337 | const resolvedRoot = path.resolve(projectRoot); |
| 338 | |
| 339 | // Check if initialized |
| 340 | if (!isInitialized(resolvedRoot)) { |
| 341 | throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`); |
| 342 | } |
| 343 | |
| 344 | // Validate directory structure |
| 345 | const validation = validateDirectory(resolvedRoot); |
| 346 | if (!validation.valid) { |
| 347 | throw new Error(`Invalid CodeGraph directory: ${validation.errors.join(', ')}`); |
| 348 | } |
| 349 | |
| 350 | // Open database |
| 351 | const dbPath = getDatabasePath(resolvedRoot); |
| 352 | const db = DatabaseConnection.open(dbPath); |
| 353 | const queries = new QueryBuilder(db.getDb()); |
| 354 | |
| 355 | const instance = new CodeGraph(db, queries, resolvedRoot); |
| 356 | |
| 357 | // Sync if requested |
| 358 | if (options.sync) { |
| 359 | await instance.sync(); |
| 360 | } |
| 361 | |
| 362 | return instance; |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Rebuild the project's database from scratch and return a fresh, empty |
no test coverage detected