MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolveModule

Function resolveModule

src/resolution/frameworks/rust.ts:331–355  ·  view source on GitHub ↗
(name: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

329}
330
331function 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}

Callers 3

reopenNameMatchedImportsFunction · 0.85
outrankedImportsFunction · 0.85
resolveFunction · 0.85

Calls 5

mapMethod · 0.80
fileExistsMethod · 0.80
getMethod · 0.65
getNodesInFileMethod · 0.65

Tested by

no test coverage detected