* Create the resolution context
()
| 333 | * Create the resolution context |
| 334 | */ |
| 335 | private createContext(): ResolutionContext { |
| 336 | return { |
| 337 | getNodesInFile: (filePath: string) => { |
| 338 | if (!this.nodeCache.has(filePath)) { |
| 339 | this.nodeCache.set(filePath, this.queries.getNodesByFile(filePath)); |
| 340 | } |
| 341 | return this.nodeCache.get(filePath)!; |
| 342 | }, |
| 343 | |
| 344 | getNodesByName: (name: string) => { |
| 345 | const cached = this.nameCache.get(name); |
| 346 | if (cached !== undefined) return cached; |
| 347 | const result = this.queries.getNodesByName(name); |
| 348 | this.nameCache.set(name, result); |
| 349 | return result; |
| 350 | }, |
| 351 | |
| 352 | getNodesByQualifiedName: (qualifiedName: string) => { |
| 353 | const cached = this.qualifiedNameCache.get(qualifiedName); |
| 354 | if (cached !== undefined) return cached; |
| 355 | const result = this.queries.getNodesByQualifiedNameExact(qualifiedName); |
| 356 | this.qualifiedNameCache.set(qualifiedName, result); |
| 357 | return result; |
| 358 | }, |
| 359 | |
| 360 | getNodesByKind: (kind: Node['kind']) => { |
| 361 | return this.queries.getNodesByKind(kind); |
| 362 | }, |
| 363 | |
| 364 | fileExists: (filePath: string) => { |
| 365 | // Check pre-built known files set first (O(1)) |
| 366 | if (this.knownFiles) { |
| 367 | const normalized = filePath.replace(/\\/g, '/'); |
| 368 | if (this.knownFiles.has(filePath) || this.knownFiles.has(normalized)) { |
| 369 | return true; |
| 370 | } |
| 371 | } |
| 372 | // Fall back to filesystem for files not yet indexed |
| 373 | const fullPath = path.join(this.projectRoot, filePath); |
| 374 | try { |
| 375 | return fs.existsSync(fullPath); |
| 376 | } catch (error) { |
| 377 | logDebug('Error checking file existence', { filePath, error: String(error) }); |
| 378 | return false; |
| 379 | } |
| 380 | }, |
| 381 | |
| 382 | readFile: (filePath: string) => { |
| 383 | if (this.fileCache.has(filePath)) { |
| 384 | return this.fileCache.get(filePath)!; |
| 385 | } |
| 386 | |
| 387 | const fullPath = path.join(this.projectRoot, filePath); |
| 388 | try { |
| 389 | const content = fs.readFileSync(fullPath, 'utf-8'); |
| 390 | this.fileCache.set(filePath, content); |
| 391 | return content; |
| 392 | } catch (error) { |
no test coverage detected