* 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 = {})
| 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 |
no test coverage detected