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

Function loadCppIncludeDirsHeuristic

src/resolution/import-resolver.ts:1891–1920  ·  view source on GitHub ↗
(projectRoot: string)

Source from the content-addressed store, hash-verified

1889 * Checks common convention directories and scans top-level dirs for headers.
1890 */
1891export function loadCppIncludeDirsHeuristic(projectRoot: string): string[] {
1892 const dirs: string[] = [];
1893 const conventionDirs = ['include', 'src', 'lib', 'api', 'inc'];
1894
1895 try {
1896 const entries = fs.readdirSync(projectRoot, { withFileTypes: true });
1897 for (const entry of entries) {
1898 if (!entry.isDirectory()) continue;
1899 const name = entry.name;
1900 // Convention directories
1901 if (conventionDirs.includes(name.toLowerCase())) {
1902 dirs.push(name);
1903 continue;
1904 }
1905 // Any top-level directory containing .h or .hpp files
1906 try {
1907 const subFiles = fs.readdirSync(path.join(projectRoot, name));
1908 if (subFiles.some(f => /\.(h|hpp|hxx|hh)$/i.test(f))) {
1909 dirs.push(name);
1910 }
1911 } catch {
1912 // ignore permission errors
1913 }
1914 }
1915 } catch {
1916 // ignore
1917 }
1918
1919 return dirs;
1920}
1921
1922/**
1923 * Resolve a C/C++ include path by searching include directories.

Callers 2

createContextMethod · 0.90
loadCppIncludeDirsFunction · 0.90

Calls 2

pushMethod · 0.80
joinMethod · 0.45

Tested by 1

loadCppIncludeDirsFunction · 0.72