MCPcopy
hub / github.com/colbymchenry/codegraph / resolveRustPathReference

Function resolveRustPathReference

src/resolution/import-resolver.ts:1565–1594  ·  view source on GitHub ↗

* Resolve a Rust qualified reference `A::B::C` by mapping the MODULE prefix * (`A::B`) to a file and finding the leaf symbol (`C`) in it. This is the Rust * analog of resolvePythonModuleMember / resolveGoCrossPackageReference * and the precise answer to common-name re-exports (`pu

(
  ref: UnresolvedRef,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

1563 * so associated-function calls and enum-variant paths fall through untouched.
1564 */
1565function resolveRustPathReference(
1566 ref: UnresolvedRef,
1567 context: ResolutionContext
1568): ResolvedRef | null {
1569 const segments = ref.referenceName.split('::').filter((s) => s.length > 0);
1570 if (segments.length < 2) return null;
1571 const leaf = segments[segments.length - 1]!;
1572 const modSegs = segments.slice(0, -1);
1573
1574 const file = resolveRustModuleFile(modSegs, ref.filePath, context);
1575 if (!file || file === ref.filePath) return null;
1576
1577 const target = context.getNodesInFile(file).find(
1578 (n) =>
1579 n.name === leaf &&
1580 (n.kind === 'function' ||
1581 n.kind === 'struct' ||
1582 n.kind === 'enum' ||
1583 n.kind === 'trait' ||
1584 n.kind === 'type_alias' ||
1585 n.kind === 'constant' ||
1586 n.kind === 'method' ||
1587 n.kind === 'class' ||
1588 n.kind === 'interface')
1589 );
1590 if (target) {
1591 return { original: ref, targetNodeId: target.id, confidence: 0.9, resolvedBy: 'import' };
1592 }
1593 return null;
1594}
1595
1596/** The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file. */
1597function rustCrateRootDir(fromFileAbs: string, context: ResolutionContext): string | null {

Callers 1

resolveViaImportFunction · 0.85

Calls 2

resolveRustModuleFileFunction · 0.85
getNodesInFileMethod · 0.65

Tested by

no test coverage detected