MCPcopy
hub / github.com/colbymchenry/codegraph / loadCppIncludeDirsHeuristic

Function loadCppIncludeDirsHeuristic

src/resolution/import-resolver.ts:476–505  ·  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

474 * Checks common convention directories and scans top-level dirs for headers.
475 */
476function 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.

Callers 1

loadCppIncludeDirsFunction · 0.85

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected