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

Function resolveRustPathReference

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

1811 * so associated-function calls and enum-variant paths fall through untouched.
1812 */
1813function resolveRustPathReference(
1814 ref: UnresolvedRef,
1815 context: ResolutionContext
1816): ResolvedRef | null {
1817 const segments = ref.referenceName.split('::').filter((s) => s.length > 0);
1818 if (segments.length < 2) return null;
1819 const leaf = segments[segments.length - 1]!;
1820 const modSegs = segments.slice(0, -1);
1821
1822 const file = resolveRustModuleFile(modSegs, ref.filePath, context);
1823 if (!file || file === ref.filePath) return null;
1824
1825 const target = context.getNodesInFile(file).find(
1826 (n) =>
1827 n.name === leaf &&
1828 (n.kind === 'function' ||
1829 n.kind === 'struct' ||
1830 n.kind === 'enum' ||
1831 n.kind === 'trait' ||
1832 n.kind === 'type_alias' ||
1833 n.kind === 'constant' ||
1834 n.kind === 'method' ||
1835 n.kind === 'class' ||
1836 n.kind === 'interface')
1837 );
1838 if (target) {
1839 return { original: ref, targetNodeId: target.id, confidence: 0.9, resolvedBy: 'import' };
1840 }
1841 return null;
1842}
1843
1844/** The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file. */
1845function 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