( cg: CodeGraph, projectRoot: string, cache: Map<string, FileCache>, filePath: string )
| 353 | } |
| 354 | |
| 355 | function loadFile( |
| 356 | cg: CodeGraph, |
| 357 | projectRoot: string, |
| 358 | cache: Map<string, FileCache>, |
| 359 | filePath: string |
| 360 | ): FileCache | null { |
| 361 | const posix = toRequestPath(filePath); |
| 362 | const hit = cache.get(posix); |
| 363 | if (hit) return hit; |
| 364 | |
| 365 | const found = findIndexedFile(cg, posix); |
| 366 | if (!found) return null; |
| 367 | |
| 368 | let entry: FileCache; |
| 369 | if (hasDriftedOnDisk(projectRoot, found.storedPath, found.record)) { |
| 370 | entry = { |
| 371 | lines: null, |
| 372 | language: found.record.language, |
| 373 | drift: true, |
| 374 | reason: |
| 375 | 'This file changed on disk after the last index sync, so the recorded call ' + |
| 376 | 'line no longer reliably points at this call. The window returns after the next sync.', |
| 377 | }; |
| 378 | } else { |
| 379 | try { |
| 380 | // The chokepoint, before anything is opened — see `source.ts`. |
| 381 | const absolute = resolveProjectFile(projectRoot, found.storedPath); |
| 382 | entry = { |
| 383 | lines: splitLines(fs.readFileSync(absolute, 'utf-8')), |
| 384 | language: found.record.language, |
| 385 | abs: absolute, |
| 386 | drift: false, |
| 387 | }; |
| 388 | } catch { |
| 389 | entry = { |
| 390 | lines: null, |
| 391 | language: found.record.language, |
| 392 | drift: false, |
| 393 | reason: 'This file is in the index but could not be read.', |
| 394 | }; |
| 395 | } |
| 396 | } |
| 397 | cache.set(posix, entry); |
| 398 | return entry; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * The ±{@link SOURCE_WINDOW} lines a card shows. |
no test coverage detected