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