(name: string, context: ResolutionContext)
| 309 | } |
| 310 | |
| 311 | function resolveModule(name: string, context: ResolutionContext): ModuleResolution | null { |
| 312 | // Rust modules can be either mod.rs in a directory or name.rs |
| 313 | const localPaths = [`src/${name}.rs`, `src/${name}/mod.rs`]; |
| 314 | |
| 315 | const workspaceCrates = getCachedCargoWorkspaceCrateMap(context); |
| 316 | const cratePath = workspaceCrates.get(name); |
| 317 | const workspacePaths = cratePath |
| 318 | ? [`${cratePath}/src/lib.rs`, `${cratePath}/src/main.rs`] |
| 319 | : []; |
| 320 | |
| 321 | const candidates: Array<{ path: string; fromWorkspace: boolean }> = [ |
| 322 | ...localPaths.map((path) => ({ path, fromWorkspace: false })), |
| 323 | ...workspacePaths.map((path) => ({ path, fromWorkspace: true })), |
| 324 | ]; |
| 325 | |
| 326 | for (const { path: modPath, fromWorkspace } of candidates) { |
| 327 | if (!context.fileExists(modPath)) continue; |
| 328 | const nodes = context.getNodesInFile(modPath); |
| 329 | const modNode = nodes.find((n) => n.kind === 'module'); |
| 330 | if (modNode) return { targetId: modNode.id, fromWorkspace }; |
| 331 | if (nodes.length > 0) return { targetId: nodes[0]!.id, fromWorkspace }; |
| 332 | } |
| 333 | |
| 334 | return null; |
| 335 | } |
no test coverage detected