(name: string, context: ResolutionContext)
| 329 | } |
| 330 | |
| 331 | function resolveModule(name: string, context: ResolutionContext): ModuleResolution | null { |
| 332 | // Rust modules can be either mod.rs in a directory or name.rs |
| 333 | const localPaths = [`src/${name}.rs`, `src/${name}/mod.rs`]; |
| 334 | |
| 335 | const workspaceCrates = getCargoWorkspaceCrateMap(context); |
| 336 | const cratePath = workspaceCrates.get(name); |
| 337 | const workspacePaths = cratePath |
| 338 | ? [`${cratePath}/src/lib.rs`, `${cratePath}/src/main.rs`] |
| 339 | : []; |
| 340 | |
| 341 | const candidates: Array<{ path: string; fromWorkspace: boolean }> = [ |
| 342 | ...localPaths.map((path) => ({ path, fromWorkspace: false })), |
| 343 | ...workspacePaths.map((path) => ({ path, fromWorkspace: true })), |
| 344 | ]; |
| 345 | |
| 346 | for (const { path: modPath, fromWorkspace } of candidates) { |
| 347 | if (!context.fileExists(modPath)) continue; |
| 348 | const nodes = context.getNodesInFile(modPath); |
| 349 | const modNode = nodes.find((n) => n.kind === 'module'); |
| 350 | if (modNode) return { targetId: modNode.id, fromWorkspace }; |
| 351 | if (nodes.length > 0) return { targetId: nodes[0]!.id, fromWorkspace }; |
| 352 | } |
| 353 | |
| 354 | return null; |
| 355 | } |
no test coverage detected