* Heuristic include directory discovery when no compile_commands.json exists. * Checks common convention directories and scans top-level dirs for headers.
(projectRoot: string)
| 648 | * Checks common convention directories and scans top-level dirs for headers. |
| 649 | */ |
| 650 | function loadCppIncludeDirsHeuristic(projectRoot: string): string[] { |
| 651 | const dirs: string[] = []; |
| 652 | const conventionDirs = ['include', 'src', 'lib', 'api', 'inc']; |
| 653 | |
| 654 | try { |
| 655 | const entries = fs.readdirSync(projectRoot, { withFileTypes: true }); |
| 656 | for (const entry of entries) { |
| 657 | if (!entry.isDirectory()) continue; |
| 658 | const name = entry.name; |
| 659 | // Convention directories |
| 660 | if (conventionDirs.includes(name.toLowerCase())) { |
| 661 | dirs.push(name); |
| 662 | continue; |
| 663 | } |
| 664 | // Any top-level directory containing .h or .hpp files |
| 665 | try { |
| 666 | const subFiles = fs.readdirSync(path.join(projectRoot, name)); |
| 667 | if (subFiles.some(f => /\.(h|hpp|hxx|hh)$/i.test(f))) { |
| 668 | dirs.push(name); |
| 669 | } |
| 670 | } catch { |
| 671 | // ignore permission errors |
| 672 | } |
| 673 | } |
| 674 | } catch { |
| 675 | // ignore |
| 676 | } |
| 677 | |
| 678 | return dirs; |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * Resolve a C/C++ include path by searching include directories. |
no test coverage detected