* Heuristic include directory discovery when no compile_commands.json exists. * Checks common convention directories and scans top-level dirs for headers.
(projectRoot: string)
| 474 | * Checks common convention directories and scans top-level dirs for headers. |
| 475 | */ |
| 476 | function loadCppIncludeDirsHeuristic(projectRoot: string): string[] { |
| 477 | const dirs: string[] = []; |
| 478 | const conventionDirs = ['include', 'src', 'lib', 'api', 'inc']; |
| 479 | |
| 480 | try { |
| 481 | const entries = fs.readdirSync(projectRoot, { withFileTypes: true }); |
| 482 | for (const entry of entries) { |
| 483 | if (!entry.isDirectory()) continue; |
| 484 | const name = entry.name; |
| 485 | // Convention directories |
| 486 | if (conventionDirs.includes(name.toLowerCase())) { |
| 487 | dirs.push(name); |
| 488 | continue; |
| 489 | } |
| 490 | // Any top-level directory containing .h or .hpp files |
| 491 | try { |
| 492 | const subFiles = fs.readdirSync(path.join(projectRoot, name)); |
| 493 | if (subFiles.some(f => /\.(h|hpp|hxx|hh)$/i.test(f))) { |
| 494 | dirs.push(name); |
| 495 | } |
| 496 | } catch { |
| 497 | // ignore permission errors |
| 498 | } |
| 499 | } |
| 500 | } catch { |
| 501 | // ignore |
| 502 | } |
| 503 | |
| 504 | return dirs; |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * Resolve a C/C++ include path by searching include directories. |
no test coverage detected