The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file.
(fromFileAbs: string, context: ResolutionContext)
| 1843 | |
| 1844 | /** The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file. */ |
| 1845 | function rustCrateRootDir(fromFileAbs: string, context: ResolutionContext): string | null { |
| 1846 | const projectRoot = context.getProjectRoot(); |
| 1847 | const toRel = (p: string) => path.relative(projectRoot, p).replace(/\\/g, '/'); |
| 1848 | let dir = path.dirname(fromFileAbs); |
| 1849 | for (let i = 0; i < 64; i++) { |
| 1850 | if (context.fileExists(toRel(path.join(dir, 'lib.rs'))) || |
| 1851 | context.fileExists(toRel(path.join(dir, 'main.rs')))) { |
| 1852 | return dir; |
| 1853 | } |
| 1854 | const parent = path.dirname(dir); |
| 1855 | if (parent === dir) return null; |
| 1856 | dir = parent; |
| 1857 | } |
| 1858 | return null; |
| 1859 | } |
| 1860 | |
| 1861 | /** Directory under which the current file's module declares its SUBMODULES. */ |
| 1862 | function rustSelfModuleDir(fromFileAbs: string): string { |
no test coverage detected