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