@@ -424,7 +424,7 @@ let references
424
424
match Document. kind doc with
425
425
| `Other -> Fiber. return None
426
426
| `Merlin doc ->
427
- let * locs , synced =
427
+ let * occurrences , synced =
428
428
Document.Merlin. dispatch_exn
429
429
~name: " occurrences"
430
430
doc
@@ -445,20 +445,22 @@ let references
445
445
| _ -> Fiber. return ()
446
446
in
447
447
Some
448
- (List. map locs ~f: (fun loc ->
449
- let range = Range. of_loc loc in
450
- let uri =
451
- match loc.loc_start.pos_fname with
452
- | "" -> uri
453
- | path -> Uri. of_path path
454
- in
455
- Log. log ~section: " debug" (fun () ->
456
- Log. msg
457
- " merlin returned fname %a"
458
- [ " pos_fname" , `String loc.loc_start.pos_fname
459
- ; " uri" , `String (Uri. to_string uri)
460
- ]);
461
- { Location. uri; range }))
448
+ (List. filter_map occurrences ~f: (function
449
+ | { loc = _ ; is_stale = true } -> None
450
+ | { loc; is_stale = false } ->
451
+ let range = Range. of_loc loc in
452
+ let uri =
453
+ match loc.loc_start.pos_fname with
454
+ | "" -> uri
455
+ | path -> Uri. of_path path
456
+ in
457
+ Log. log ~section: " debug" (fun () ->
458
+ Log. msg
459
+ " merlin returned fname %a"
460
+ [ " pos_fname" , `String loc.loc_start.pos_fname
461
+ ; " uri" , `String (Uri. to_string uri)
462
+ ]);
463
+ Some { Location. uri; range }))
462
464
;;
463
465
464
466
let highlight
@@ -470,14 +472,15 @@ let highlight
470
472
match Document. kind doc with
471
473
| `Other -> Fiber. return None
472
474
| `Merlin m ->
473
- let + locs , _synced =
475
+ let + occurrences , _synced =
474
476
Document.Merlin. dispatch_exn
475
477
~name: " occurrences"
476
478
m
477
479
(Occurrences (`Ident_at (Position. logical position), `Buffer ))
478
480
in
479
481
let lsp_locs =
480
- List. filter_map locs ~f: (fun loc ->
482
+ List. filter_map occurrences ~f: (fun (occurrence : Query_protocol.occurrence ) ->
483
+ let loc = occurrence.loc in
481
484
let range = Range. of_loc loc in
482
485
(* filter out multi-line ranges, since those are very noisy and happen
483
486
a lot with certain PPXs *)
@@ -660,16 +663,19 @@ let on_request
660
663
match Document. kind doc with
661
664
| `Other -> Fiber. return None
662
665
| `Merlin doc ->
663
- let + locs , _synced =
666
+ let + occurrences , _synced =
664
667
Document.Merlin. dispatch_exn
665
668
~name: " occurrences"
666
669
doc
667
670
(Occurrences (`Ident_at (Position. logical position), `Buffer ))
668
671
in
669
672
let loc =
670
- List. find_opt locs ~f: (fun loc ->
673
+ List. find_map occurrences ~f: (fun (occurrence : Query_protocol.occurrence ) ->
674
+ let loc = occurrence.loc in
671
675
let range = Range. of_loc loc in
672
- Position. compare_inclusion position range = `Inside )
676
+ match occurrence.is_stale, Position. compare_inclusion position range with
677
+ | false , `Inside -> Some loc
678
+ | true , _ | _ , `Outside _ -> None )
673
679
in
674
680
Option. map loc ~f: Range. of_loc)
675
681
()
0 commit comments