@@ -145,12 +145,23 @@ let getConstructor (file : File.t) stamp name =
145
145
| Some const -> Some const)
146
146
| _ -> None )
147
147
148
- let exportedForTip ~(env : QueryEnv.t ) ~name (tip : Tip.t ) =
149
- match tip with
150
- | Value -> Exported. find env.exported Exported. Value name
151
- | Field _ | Constructor _ | Type ->
152
- Exported. find env.exported Exported. Type name
153
- | Module -> Exported. find env.exported Exported. Module name
148
+ let exportedForTip ~env ~path ~package ~(tip : Tip.t ) =
149
+ match ResolvePath. resolvePath ~env ~path ~package with
150
+ | None ->
151
+ Log. log (" Cannot resolve path " ^ pathToString path);
152
+ None
153
+ | Some (env , name ) -> (
154
+ let kind =
155
+ match tip with
156
+ | Value -> Exported. Value
157
+ | Field _ | Constructor _ | Type -> Exported. Type
158
+ | Module -> Exported. Module
159
+ in
160
+ match Exported. find env.exported kind name with
161
+ | None ->
162
+ Log. log (" Exported not found for tip " ^ name ^ " > " ^ Tip. toString tip);
163
+ None
164
+ | Some stamp -> Some (env, name, stamp))
154
165
155
166
let definedForLoc ~file ~package locKind =
156
167
let inner ~file stamp (tip : Tip.t ) =
@@ -180,25 +191,17 @@ let definedForLoc ~file ~package locKind =
180
191
None
181
192
| Some file -> (
182
193
let env = QueryEnv. fromFile file in
183
- match ResolvePath. resolvePath ~env ~path ~package with
184
- | None ->
185
- Log. log (" Cannot resolve path " ^ pathToString path);
186
- None
187
- | Some (env , name ) -> (
188
- match exportedForTip ~env ~name tip with
194
+ match exportedForTip ~env ~path ~package ~tip with
195
+ | None -> None
196
+ | Some (env , name , stamp ) -> (
197
+ maybeLog (" Getting for " ^ string_of_int stamp ^ " in " ^ name);
198
+ match inner ~file: env.file stamp tip with
189
199
| None ->
190
- Log. log
191
- (" Exported not found for tip " ^ name ^ " > " ^ Tip. toString tip);
200
+ Log. log " could not get defined" ;
192
201
None
193
- | Some stamp -> (
194
- maybeLog (" Getting for " ^ string_of_int stamp ^ " in " ^ name);
195
- match inner ~file: env.file stamp tip with
196
- | None ->
197
- Log. log " could not get defined" ;
198
- None
199
- | Some res ->
200
- maybeLog " Yes!! got it" ;
201
- Some res))))
202
+ | Some res ->
203
+ maybeLog " Yes!! got it" ;
204
+ Some res)))
202
205
203
206
(* * Find alternative declaration: from res in case of interface, or from resi in case of implementation *)
204
207
let alternateDeclared ~(file : File.t ) ~package (declared : _ Declared.t ) tip =
@@ -217,12 +220,10 @@ let alternateDeclared ~(file : File.t) ~package (declared : _ Declared.t) tip =
217
220
let path = ModulePath. toPath declared.modulePath declared.name.txt in
218
221
maybeLog (" find declared for path " ^ pathToString path);
219
222
let declaredOpt =
220
- match ResolvePath. resolvePath ~env ~path ~package with
223
+ match exportedForTip ~env ~path ~package ~tip with
221
224
| None -> None
222
- | Some (env , name ) -> (
223
- match exportedForTip ~env ~name tip with
224
- | None -> None
225
- | Some stamp -> declaredForTip ~stamps: file.stamps stamp tip)
225
+ | Some (_env , _name , stamp ) ->
226
+ declaredForTip ~stamps: file.stamps stamp tip
226
227
in
227
228
match declaredOpt with
228
229
| None -> None
@@ -373,16 +374,12 @@ let definitionForLocItem ~full:{file; package} locItem =
373
374
| None -> None
374
375
| Some file -> (
375
376
let env = QueryEnv. fromFile file in
376
- match ResolvePath. resolvePath ~env ~path ~package with
377
+ match exportedForTip ~env ~path ~package ~tip with
377
378
| None -> None
378
- | Some (env , name ) -> (
379
- maybeLog (" resolved path:" ^ name);
380
- match exportedForTip ~env ~name tip with
381
- | None -> None
382
- | Some stamp ->
383
- (* oooh wht do I do if the stamp is inside a pseudo-file? *)
384
- maybeLog (" Got stamp " ^ string_of_int stamp);
385
- definition ~file: env.file ~package stamp tip)))
379
+ | Some (env , _name , stamp ) ->
380
+ (* oooh wht do I do if the stamp is inside a pseudo-file? *)
381
+ maybeLog (" Got stamp " ^ string_of_int stamp);
382
+ definition ~file: env.file ~package stamp tip))
386
383
387
384
let digConstructor ~env ~package path =
388
385
match ResolvePath. resolveFromCompilerPath ~env ~package path with
@@ -557,17 +554,14 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
557
554
| None -> []
558
555
| Some file -> (
559
556
let env = QueryEnv. fromFile file in
560
- match ResolvePath. resolvePath ~env ~path ~package with
557
+ match exportedForTip ~env ~path ~package ~tip with
561
558
| None -> []
562
- | Some (env , name ) -> (
563
- match exportedForTip ~ env ~name tip with
559
+ | Some (env , _name , stamp ) -> (
560
+ match Cmt. fullFromUri ~uri: env.file.uri with
564
561
| None -> []
565
- | Some stamp -> (
566
- match Cmt. fullFromUri ~uri: env.file.uri with
567
- | None -> []
568
- | Some full ->
569
- maybeLog
570
- (" Finding references for (global) " ^ Uri. toString env.file.uri
571
- ^ " and stamp " ^ string_of_int stamp ^ " and tip "
572
- ^ Tip. toString tip);
573
- forLocalStamp ~full stamp tip))))
562
+ | Some full ->
563
+ maybeLog
564
+ (" Finding references for (global) " ^ Uri. toString env.file.uri
565
+ ^ " and stamp " ^ string_of_int stamp ^ " and tip "
566
+ ^ Tip. toString tip);
567
+ forLocalStamp ~full stamp tip)))
0 commit comments