@@ -46,8 +46,8 @@ let locForPos ~extra pos =
46
46
arg has the location range of arg
47
47
heuristic for: [Props, arg], give loc of `arg` *)
48
48
(* Printf.eprintf "l1 %s\nl2 %s\n"
49
- (SharedTypes.locationToString _l1)
50
- (SharedTypes.locationToString l2); *)
49
+ (SharedTypes.locationToString _l1)
50
+ (SharedTypes.locationToString l2); *)
51
51
Some l2
52
52
| [(loc1, _); ((loc2, _) as l); (loc3, _)] when loc1 = loc2 && loc2 = loc3 ->
53
53
(* JSX with at most one child
@@ -301,3 +301,149 @@ let definitionForLoc ~pathsForModule ~file ~getUri ~getModule loc =
301
301
(* oooh wht do I do if the stamp is inside a pseudo-file? *)
302
302
maybeLog (" Got stamp " ^ string_of_int stamp);
303
303
definition ~file: env.file ~get Module stamp tip)))
304
+
305
+ let isVisible (declared : _ SharedTypes.declared ) =
306
+ declared.exported
307
+ &&
308
+ let rec loop v =
309
+ match v with
310
+ | File _ -> true
311
+ | NotVisible -> false
312
+ | IncludedModule (_ , inner ) -> loop inner
313
+ | ExportedModule (_ , inner ) -> loop inner
314
+ in
315
+ loop declared.modulePath
316
+
317
+ let rec pathFromVisibility visibilityPath current =
318
+ match visibilityPath with
319
+ | File _ -> Some current
320
+ | IncludedModule (_ , inner ) -> pathFromVisibility inner current
321
+ | ExportedModule (name , inner ) ->
322
+ pathFromVisibility inner (Nested (name, current))
323
+ | NotVisible -> None
324
+
325
+ let pathFromVisibility visibilityPath tipName =
326
+ pathFromVisibility visibilityPath (Tip tipName)
327
+
328
+ let forLocalStamp ~pathsForModule ~file ~extra ~allModules ~getModule ~getUri
329
+ ~getExtra stamp tip =
330
+ let env = Query. fileEnv file in
331
+ let open Infix in
332
+ match
333
+ match tip with
334
+ | Constructor name ->
335
+ Query. getConstructor file stamp name |?>> fun x -> x.stamp
336
+ | Field name -> Query. getField file stamp name |?>> fun x -> x.stamp
337
+ | _ -> Some stamp
338
+ with
339
+ | None -> []
340
+ | Some localStamp -> (
341
+ match Hashtbl. find_opt extra.internalReferences localStamp with
342
+ | None -> []
343
+ | Some local ->
344
+ maybeLog (" Checking externals: " ^ string_of_int stamp);
345
+ let externals =
346
+ match Query. declaredForTip ~stamps: env.file.stamps stamp tip with
347
+ | None -> []
348
+ | Some declared ->
349
+ if isVisible declared then (
350
+ let alternativeReferences =
351
+ match
352
+ alternateDeclared ~paths ForModule ~file ~get Uri declared tip
353
+ with
354
+ | None -> []
355
+ | Some (file , extra , {stamp} ) -> (
356
+ match
357
+ match tip with
358
+ | Constructor name ->
359
+ Query. getConstructor file stamp name |?>> fun x -> x.stamp
360
+ | Field name ->
361
+ Query. getField file stamp name |?>> fun x -> x.stamp
362
+ | _ -> Some stamp
363
+ with
364
+ | None -> []
365
+ | Some localStamp -> (
366
+ match
367
+ Hashtbl. find_opt extra.internalReferences localStamp
368
+ with
369
+ | None -> []
370
+ | Some local -> [(file.uri, local)]))
371
+ (* if this file has a corresponding interface or implementation file
372
+ also find the references in that file *)
373
+ in
374
+ match pathFromVisibility declared.modulePath declared.name.txt with
375
+ | None -> []
376
+ | Some path ->
377
+ maybeLog (" Now checking path " ^ pathToString path);
378
+ let thisModuleName = file.moduleName in
379
+ let externals =
380
+ allModules
381
+ |> List. filter (fun name -> name <> file.moduleName)
382
+ |> Utils. filterMap (fun name ->
383
+ match getModule name with
384
+ | None -> None
385
+ | Some file -> (
386
+ match getExtra name with
387
+ | None -> None
388
+ | Some extra -> (
389
+ match
390
+ Hashtbl. find_opt extra.externalReferences
391
+ thisModuleName
392
+ with
393
+ | None -> None
394
+ | Some refs ->
395
+ let refs =
396
+ refs
397
+ |> Utils. filterMap (fun (p , t , l ) ->
398
+ match p = path && t = tip with
399
+ | true -> Some l
400
+ | false -> None )
401
+ in
402
+ Some (file.uri, refs))))
403
+ in
404
+ alternativeReferences @ externals)
405
+ else (
406
+ maybeLog " Not visible" ;
407
+ [] )
408
+ in
409
+ (file.uri, local) :: externals)
410
+
411
+ let allReferencesForLoc ~pathsForModule ~getUri ~file ~extra ~allModules
412
+ ~getModule ~getExtra loc =
413
+ match loc with
414
+ | Explanation _
415
+ | Typed (_, NotFound )
416
+ | LModule NotFound
417
+ | TopLevelModule _ | Constant _ ->
418
+ []
419
+ | TypeDefinition (_ , _ , stamp ) ->
420
+ forLocalStamp ~paths ForModule ~get Uri ~file ~extra ~all Modules ~get Module
421
+ ~get Extra stamp Type
422
+ | Typed (_, (LocalReference (stamp, tip) | Definition (stamp, tip)))
423
+ | LModule (LocalReference (stamp , tip ) | Definition (stamp , tip )) ->
424
+ maybeLog
425
+ (" Finding references for " ^ Uri2. toString file.uri ^ " and stamp "
426
+ ^ string_of_int stamp ^ " and tip " ^ tipToString tip);
427
+ forLocalStamp ~paths ForModule ~get Uri ~file ~extra ~all Modules ~get Module
428
+ ~get Extra stamp tip
429
+ | LModule (GlobalReference (moduleName, path, tip))
430
+ | Typed (_ , GlobalReference (moduleName , path , tip )) -> (
431
+ match getModule moduleName with
432
+ | None -> []
433
+ | Some file -> (
434
+ let env = Query. fileEnv file in
435
+ match Query. resolvePath ~env ~path ~get Module with
436
+ | None -> []
437
+ | Some (env , name ) -> (
438
+ match Query. exportedForTip ~env name tip with
439
+ | None -> []
440
+ | Some stamp -> (
441
+ match getUri env.file.uri with
442
+ | Error _ -> []
443
+ | Ok (file , extra ) ->
444
+ maybeLog
445
+ (" Finding references for (global) " ^ Uri2. toString env.file.uri
446
+ ^ " and stamp " ^ string_of_int stamp ^ " and tip "
447
+ ^ tipToString tip);
448
+ forLocalStamp ~paths ForModule ~get Uri ~file ~extra ~all Modules
449
+ ~get Module ~get Extra stamp tip))))
0 commit comments