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

Function resolveModule

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

Source from the content-addressed store, hash-verified

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

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