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

Function resolveRustPathReference

src/resolution/import-resolver.ts:1828–1858  ·  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

1826 * so associated-function calls and enum-variant paths fall through untouched.
1827 */
1828function resolveRustPathReference(
1829 ref: UnresolvedRef,
1830 context: ResolutionContext
1831): ResolvedRef | null {
1832 const segments = ref.referenceName.split('::').filter((s) => s.length > 0);
1833 if (segments.length < 2) return null;
1834 const leaf = segments[segments.length - 1]!;
1835 const modSegs = segments.slice(0, -1);
1836
1837 const file = resolveRustModuleFile(modSegs, ref.filePath, context);
1838 if (!file || file === ref.filePath) return null;
1839
1840 const target = context.getNodesInFile(file).find(
1841 (n) =>
1842 n.name === leaf &&
1843 (n.kind === 'function' ||
1844 n.kind === 'struct' ||
1845 n.kind === 'union' ||
1846 n.kind === 'enum' ||
1847 n.kind === 'trait' ||
1848 n.kind === 'type_alias' ||
1849 n.kind === 'constant' ||
1850 n.kind === 'method' ||
1851 n.kind === 'class' ||
1852 n.kind === 'interface')
1853 );
1854 if (target) {
1855 return { original: ref, targetNodeId: target.id, confidence: 0.9, resolvedBy: 'import' };
1856 }
1857 return null;
1858}
1859
1860/** The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file. */
1861function 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