| 1889 | * Checks common convention directories and scans top-level dirs for headers. |
| 1890 | */ |
| 1891 | export 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. |