Skip to content

Commit c8e806e

Browse files
panglesdjonludlam
authored andcommitted
Occurrences: remove duplicated source infos
Some subnodes of hidden nodes were generating twice the infos Signed-off-by: Paul-Elliot <[email protected]>
1 parent 981b159 commit c8e806e

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/loader/implementation.ml

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ module IdentHashtbl = Hashtbl.Make (struct
137137
let hash = Hashtbl.hash
138138
end)
139139

140+
module AnnotHashtbl = Hashtbl.Make (struct
141+
type t = Odoc_model.Lang.Source_info.annotation Odoc_model.Lang.Source_info.with_pos
142+
let equal l1 l2 = l1 = l2
143+
let hash = Hashtbl.hash
144+
end)
145+
140146
module UidHashtbl = Shape.Uid.Tbl
141147

142148
(* Adds the local definitions found in traverse infos to the [loc_to_id] and
@@ -277,17 +283,18 @@ let populate_global_defs env source_id loc_to_id uid_to_loc uid_to_id =
277283
| _ -> ()))
278284
uid_to_loc
279285

280-
let (>>=) a b = Option.map b a
281-
282286
(* Extract [Typedtree_traverse] occurrence information and turn them into proper
283287
source infos *)
284288
let process_occurrences env poses loc_to_id local_ident_to_loc =
285289
let open Odoc_model.Lang.Source_info in
290+
(* Ensure source infos are not repeated by putting them in a Set (a unit hashtbl) *)
291+
let occ_tbl = AnnotHashtbl.create 100 in
286292
let process p find_in_env =
287293
match p with
288294
| Path.Pident id when IdentHashtbl.mem local_ident_to_loc id -> (
289295
match
290-
LocHashtbl.find_opt loc_to_id (IdentHashtbl.find local_ident_to_loc id)
296+
LocHashtbl.find_opt loc_to_id
297+
(IdentHashtbl.find local_ident_to_loc id)
291298
with
292299
| None -> None
293300
| Some id ->
@@ -301,29 +308,30 @@ let process_occurrences env poses loc_to_id local_ident_to_loc =
301308
Some { documentation; implementation }
302309
| exception _ -> None)
303310
in
304-
List.filter_map
311+
List.iter
305312
(function
306313
| Typedtree_traverse.Analysis.Value p, loc ->
307-
process p Ident_env.Path.read_value >>= fun l ->
308-
(Value l, pos_of_loc loc)
314+
process p Ident_env.Path.read_value |> Option.iter @@ fun l ->
315+
AnnotHashtbl.replace occ_tbl (Value l, pos_of_loc loc) ()
309316
| Module p, loc ->
310-
process p Ident_env.Path.read_module >>= fun l ->
311-
(Module l, pos_of_loc loc)
317+
process p Ident_env.Path.read_module |> Option.iter @@ fun l ->
318+
AnnotHashtbl.replace occ_tbl (Module l, pos_of_loc loc) ()
312319
| ClassType p, loc ->
313-
process p Ident_env.Path.read_class_type >>= fun l ->
314-
(ClassType l, pos_of_loc loc)
320+
process p Ident_env.Path.read_class_type |> Option.iter @@ fun l ->
321+
AnnotHashtbl.replace occ_tbl (ClassType l, pos_of_loc loc) ()
315322
| ModuleType p, loc ->
316-
process p Ident_env.Path.read_module_type >>= fun l ->
317-
(ModuleType l, pos_of_loc loc)
323+
process p Ident_env.Path.read_module_type |> Option.iter @@ fun l ->
324+
AnnotHashtbl.replace occ_tbl (ModuleType l, pos_of_loc loc) ()
318325
| Type p, loc ->
319-
process p Ident_env.Path.read_type >>= fun l ->
320-
(Type l, pos_of_loc loc)
326+
process p Ident_env.Path.read_type |> Option.iter @@ fun l ->
327+
AnnotHashtbl.replace occ_tbl (Type l, pos_of_loc loc) ()
321328
| Constructor _p, loc ->
322-
(* process p Ident_env.Path.read_constructor *) None >>= fun l ->
323-
(Constructor l, pos_of_loc loc)
324-
| LocalDefinition _, _ -> None)
325-
poses
326-
329+
(* process p Ident_env.Path.read_constructor *)
330+
None |> Option.iter @@ fun l ->
331+
AnnotHashtbl.replace occ_tbl (Constructor l, pos_of_loc loc) ()
332+
| LocalDefinition _, _ -> ())
333+
poses;
334+
AnnotHashtbl.fold (fun k () acc -> k :: acc) occ_tbl []
327335

328336
(* Add definition source info from the [loc_to_id] table *)
329337
let add_definitions loc_to_id occurrences =

0 commit comments

Comments
 (0)