MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / resolveModule

Function resolveModule

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

Source from the content-addressed store, hash-verified

309}
310
311function 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}

Callers 1

resolveFunction · 0.85

Calls 4

fileExistsMethod · 0.80
getMethod · 0.65
getNodesInFileMethod · 0.65

Tested by

no test coverage detected