* 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 )
| 2084 | * so associated-function calls and enum-variant paths fall through untouched. |
| 2085 | */ |
| 2086 | function resolveRustPathReference( |
| 2087 | ref: UnresolvedRef, |
| 2088 | context: ResolutionContext |
| 2089 | ): ResolvedRef | null { |
| 2090 | const segments = ref.referenceName.split('::').filter((s) => s.length > 0); |
| 2091 | if (segments.length < 2) return null; |
| 2092 | const leaf = segments[segments.length - 1]!; |
| 2093 | const modSegs = segments.slice(0, -1); |
| 2094 | |
| 2095 | const file = resolveRustModuleFile(modSegs, ref.filePath, context); |
| 2096 | if (!file || file === ref.filePath) return null; |
| 2097 | |
| 2098 | const target = context.getNodesInFile(file).find( |
| 2099 | (n) => |
| 2100 | n.name === leaf && |
| 2101 | (n.kind === 'function' || |
| 2102 | n.kind === 'struct' || |
| 2103 | n.kind === 'union' || |
| 2104 | n.kind === 'enum' || |
| 2105 | n.kind === 'trait' || |
| 2106 | n.kind === 'type_alias' || |
| 2107 | n.kind === 'constant' || |
| 2108 | n.kind === 'method' || |
| 2109 | n.kind === 'class' || |
| 2110 | n.kind === 'interface') |
| 2111 | ); |
| 2112 | if (target) { |
| 2113 | return { original: ref, targetNodeId: target.id, confidence: 0.9, resolvedBy: 'import' }; |
| 2114 | } |
| 2115 | return null; |
| 2116 | } |
| 2117 | |
| 2118 | /** The crate-root directory (holds `lib.rs`/`main.rs`), walking up from a file. */ |
| 2119 | function rustCrateRootDir(fromFileAbs: string, context: ResolutionContext): string | null { |
no test coverage detected