MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / loadCppIncludeDirsHeuristic

Function loadCppIncludeDirsHeuristic

src/resolution/import-resolver.ts:650–679  ·  view source on GitHub ↗

* Heuristic include directory discovery when no compile_commands.json exists. * Checks common convention directories and scans top-level dirs for headers.

(projectRoot: string)

Source from the content-addressed store, hash-verified

648 * Checks common convention directories and scans top-level dirs for headers.
649 */
650function 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.

Callers 1

loadCppIncludeDirsFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected