The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file.
(fromFileAbs: string, context: ResolutionContext)
| 1595 | |
| 1596 | /** The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file. */ |
| 1597 | function rustCrateRootDir(fromFileAbs: string, context: ResolutionContext): string | null { |
| 1598 | const projectRoot = context.getProjectRoot(); |
| 1599 | const toRel = (p: string) => path.relative(projectRoot, p).replace(/\\/g, '/'); |
| 1600 | let dir = path.dirname(fromFileAbs); |
| 1601 | for (let i = 0; i < 64; i++) { |
| 1602 | if (context.fileExists(toRel(path.join(dir, 'lib.rs'))) || |
| 1603 | context.fileExists(toRel(path.join(dir, 'main.rs')))) { |
| 1604 | return dir; |
| 1605 | } |
| 1606 | const parent = path.dirname(dir); |
| 1607 | if (parent === dir) return null; |
| 1608 | dir = parent; |
| 1609 | } |
| 1610 | return null; |
| 1611 | } |
| 1612 | |
| 1613 | /** Directory under which the current file's module declares its SUBMODULES. */ |
| 1614 | function rustSelfModuleDir(fromFileAbs: string): string { |
no test coverage detected