@@ -145,7 +145,7 @@ 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 ) =
148
+ let exportedForTip ~(env : QueryEnv.t ) ~ name (tip : Tip.t ) =
149
149
match tip with
150
150
| Value -> Exported. find env.exported Exported. Value name
151
151
| Field _ | Constructor _ | Type ->
@@ -185,7 +185,7 @@ let definedForLoc ~file ~package locKind =
185
185
Log. log (" Cannot resolve path " ^ pathToString path);
186
186
None
187
187
| Some (env , name ) -> (
188
- match exportedForTip ~env name tip with
188
+ match exportedForTip ~env ~ name tip with
189
189
| None ->
190
190
Log. log
191
191
(" Exported not found for tip " ^ name ^ " > " ^ Tip. toString tip);
@@ -200,23 +200,6 @@ let definedForLoc ~file ~package locKind =
200
200
maybeLog " Yes!! got it" ;
201
201
Some res))))
202
202
203
- let declaredForExportedTip ~(stamps : Stamps.t ) ~(exported : Exported.t ) name
204
- (tip : Tip.t ) =
205
- let bind f x = Option. bind x f in
206
- match tip with
207
- | Value ->
208
- Exported. find exported Exported. Value name
209
- |> bind (fun stamp -> Stamps. findValue stamps stamp)
210
- |> Option. map (fun x -> {x with Declared. item = () })
211
- | Field _ | Constructor _ | Type ->
212
- Exported. find exported Exported. Type name
213
- |> bind (fun stamp -> Stamps. findType stamps stamp)
214
- |> Option. map (fun x -> {x with Declared. item = () })
215
- | Module ->
216
- Exported. find exported Exported. Module name
217
- |> bind (fun stamp -> Stamps. findModule stamps stamp)
218
- |> Option. map (fun x -> {x with Declared. item = () })
219
-
220
203
(* * Find alternative declaration: from res in case of interface, or from resi in case of implementation *)
221
204
let alternateDeclared ~(file : File.t ) ~package (declared : _ Declared.t ) tip =
222
205
match Hashtbl. find_opt package.pathsForModule file.moduleName with
@@ -230,10 +213,18 @@ let alternateDeclared ~(file : File.t) ~package (declared : _ Declared.t) tip =
230
213
match Cmt. fullFromUri ~uri: (Uri. fromPath alternateUri) with
231
214
| None -> None
232
215
| Some {file; extra} -> (
233
- match
234
- declaredForExportedTip ~stamps: file.stamps
235
- ~exported: file.structure.exported declared.name.txt tip
236
- with
216
+ let env = QueryEnv. fromFile file in
217
+ let path = ModulePath. toPath declared.modulePath declared.name.txt in
218
+ maybeLog (" find declared for path " ^ pathToString path);
219
+ let declaredOpt =
220
+ match ResolvePath. resolvePath ~env ~path ~package with
221
+ | 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)
226
+ in
227
+ match declaredOpt with
237
228
| None -> None
238
229
| Some declared -> Some (file, extra, declared)))
239
230
| _ ->
@@ -386,7 +377,7 @@ let definitionForLocItem ~full:{file; package} locItem =
386
377
| None -> None
387
378
| Some (env , name ) -> (
388
379
maybeLog (" resolved path:" ^ name);
389
- match exportedForTip ~env name tip with
380
+ match exportedForTip ~env ~ name tip with
390
381
| None -> None
391
382
| Some stamp ->
392
383
(* oooh wht do I do if the stamp is inside a pseudo-file? *)
@@ -425,7 +416,7 @@ let typeDefinitionForLocItem ~full:{file; package} locItem =
425
416
let isVisible (declared : _ Declared.t ) =
426
417
declared.isExported
427
418
&&
428
- let rec loop v =
419
+ let rec loop ( v : ModulePath.t ) =
429
420
match v with
430
421
| File _ -> true
431
422
| NotVisible -> false
@@ -434,17 +425,6 @@ let isVisible (declared : _ Declared.t) =
434
425
in
435
426
loop declared.modulePath
436
427
437
- let rec pathFromVisibility visibilityPath current =
438
- match visibilityPath with
439
- | File _ -> Some current
440
- | IncludedModule (_ , inner ) -> pathFromVisibility inner current
441
- | ExportedModule {name; modulePath = inner } ->
442
- pathFromVisibility inner (name :: current)
443
- | NotVisible -> None
444
-
445
- let pathFromVisibility visibilityPath tipName =
446
- pathFromVisibility visibilityPath [tipName]
447
-
448
428
type references = {
449
429
uri : Uri .t ;
450
430
locOpt : Location .t option ; (* None: reference to a toplevel module *)
@@ -497,35 +477,35 @@ let forLocalStamp ~full:{file; extra; package} stamp (tip : Tip.t) =
497
477
(* if this file has a corresponding interface or implementation file
498
478
also find the references in that file *)
499
479
in
500
- match pathFromVisibility declared.modulePath declared.name.txt with
501
- | None -> []
502
- | Some path ->
503
- maybeLog (" Now checking path " ^ pathToString path);
504
- let thisModuleName = file.moduleName in
505
- let externals =
506
- package.projectFiles |> FileSet. elements
507
- |> List. filter (fun name -> name <> file.moduleName)
508
- |> List. map (fun moduleName ->
509
- Cmt. fullsFromModule ~package ~module Name
510
- |> List. map (fun {file; extra} ->
511
- match
512
- Hashtbl. find_opt extra.externalReferences
513
- thisModuleName
514
- with
515
- | None -> []
516
- | Some refs ->
517
- let locs =
518
- refs
519
- |> Utils. filterMap (fun (p , t , locs ) ->
520
- if p = path && t = tip then Some locs
521
- else None )
522
- in
523
- locs
524
- |> List. map (fun loc ->
525
- {uri = file.uri; locOpt = Some loc})))
526
- |> List. concat |> List. concat
527
- in
528
- alternativeReferences @ externals)
480
+ let path =
481
+ ModulePath. toPath declared.modulePath declared.name.txt
482
+ in
483
+ maybeLog (" Now checking path " ^ pathToString path);
484
+ let thisModuleName = file.moduleName in
485
+ let externals =
486
+ package.projectFiles |> FileSet. elements
487
+ |> List. filter (fun name -> name <> file.moduleName)
488
+ |> List. map (fun moduleName ->
489
+ Cmt. fullsFromModule ~package ~module Name
490
+ |> List. map (fun {file; extra} ->
491
+ match
492
+ Hashtbl. find_opt extra.externalReferences
493
+ thisModuleName
494
+ with
495
+ | None -> []
496
+ | Some refs ->
497
+ let locs =
498
+ refs
499
+ |> Utils. filterMap (fun (p , t , locs ) ->
500
+ if p = path && t = tip then Some locs
501
+ else None )
502
+ in
503
+ locs
504
+ |> List. map (fun loc ->
505
+ {uri = file.uri; locOpt = Some loc})))
506
+ |> List. concat |> List. concat
507
+ in
508
+ alternativeReferences @ externals)
529
509
else (
530
510
maybeLog " Not visible" ;
531
511
[] )
@@ -580,7 +560,7 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
580
560
match ResolvePath. resolvePath ~env ~path ~package with
581
561
| None -> []
582
562
| Some (env , name ) -> (
583
- match exportedForTip ~env name tip with
563
+ match exportedForTip ~env ~ name tip with
584
564
| None -> []
585
565
| Some stamp -> (
586
566
match Cmt. fullFromUri ~uri: env.file.uri with
0 commit comments