@@ -15,6 +15,17 @@ let set_fname ~file (loc : Location.t) =
1515 loc_end = { loc.loc_end with pos_fname }
1616 }
1717
18+ (* Merlin-jst: Upstream Merlin only includes the location of the last segment of an
19+ identifier. (ex: If the user wrote "Foo.bar", only the location of "bar") is included.
20+ We instead choose to include the entire "Foo.bar", for two reasons:
21+ 1. We think that this is a slightly better user experience
22+ 2. Upstream Merlin does not include occurrences within ppx generated code, but we do.
23+ Because of this, it is not always true for us that the reported location in the
24+ buffer is text corresponding to the identifier. (For example, the location may
25+ correspond to a ppx extension node.) In such a case, attempting to modify the
26+ location to only include the last segment of the identifier is nonsensical. Since we
27+ don't have a way to detect such a case, it forces us to not try. *)
28+ (*
1829(* A longident can have the form: A.B.x Right now we are only interested in
1930 values, but we will eventually want to index all occurrences of modules in
2031 such longidents. However there is an issue with that: we only have the
@@ -39,6 +50,7 @@ let last_loc (loc : Location.t) lid =
3950 { loc.loc_end with pos_cnum = loc.loc_end.pos_cnum - last_size }
4051 }
4152 else loc
53+ *)
4254
4355let uid_and_loc_of_node env node =
4456 let open Browse_raw in
@@ -200,18 +212,25 @@ let locs_of ~config ~env ~typer_result ~pos ~scope path =
200212 Option. map external_locs ~f: (fun (index , locs ) ->
201213 let stats = Stat_check. create ~cache_size: 128 index in
202214 ( Lid_set. filter
203- (fun { loc; _ } ->
204- (* We ignore external results that concern the current buffer *)
205- let file = loc.Location. loc_start.Lexing. pos_fname in
206- let file, buf =
207- match config.merlin.source_root with
208- | Some root ->
209- (Filename. concat root file, current_buffer_path)
210- | None -> (file, config.query.filename)
215+ (fun ({ loc; _ } as lid ) ->
216+ let is_current_buffer =
217+ (* We filter external results that concern the current buffer *)
218+ let file = loc.Location. loc_start.Lexing. pos_fname in
219+ let file, buf =
220+ match config.merlin.source_root with
221+ | Some root ->
222+ (Filename. concat root file, current_buffer_path)
223+ | None -> (file, config.query.filename)
224+ in
225+ let file = Misc. canonicalize_filename file in
226+ let buf = Misc. canonicalize_filename buf in
227+ String. equal file buf
211228 in
212- let file = Misc. canonicalize_filename file in
213- let buf = Misc. canonicalize_filename buf in
214- if String. equal file buf then false
229+ let should_be_ignored =
230+ (* We ignore results that don't have a location *)
231+ Index_occurrences. should_ignore_lid lid
232+ in
233+ if is_current_buffer || should_be_ignored then false
215234 else begin
216235 (* We ignore external results if their source was modified *)
217236 let check = Stat_check. check stats ~file in
@@ -249,7 +268,9 @@ let locs_of ~config ~env ~typer_result ~pos ~scope path =
249268 let lid = try Longident. head txt with _ -> " not flat lid" in
250269 log ~title: " occurrences" " Found occ: %s %a" lid Logger. fmt
251270 (Fun. flip Location. print_loc loc);
252- let loc = last_loc loc txt in
271+ (* Merlin-jst: See comment at the commented-out definition of last_loc for
272+ explanation of why this is commented out. *)
273+ (* let loc = last_loc loc txt in *)
253274 let fname = loc.Location. loc_start.Lexing. pos_fname in
254275 if not (Filename. is_relative fname) then Some loc
255276 else
0 commit comments