@@ -137,6 +137,12 @@ module IdentHashtbl = Hashtbl.Make (struct
137
137
let hash = Hashtbl. hash
138
138
end )
139
139
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
+
140
146
module UidHashtbl = Shape.Uid. Tbl
141
147
142
148
(* 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 =
277
283
| _ -> () ))
278
284
uid_to_loc
279
285
280
- let (>>=) a b = Option. map b a
281
-
282
286
(* Extract [Typedtree_traverse] occurrence information and turn them into proper
283
287
source infos *)
284
288
let process_occurrences env poses loc_to_id local_ident_to_loc =
285
289
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
286
292
let process p find_in_env =
287
293
match p with
288
294
| Path. Pident id when IdentHashtbl. mem local_ident_to_loc id -> (
289
295
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)
291
298
with
292
299
| None -> None
293
300
| Some id ->
@@ -301,29 +308,30 @@ let process_occurrences env poses loc_to_id local_ident_to_loc =
301
308
Some { documentation; implementation }
302
309
| exception _ -> None )
303
310
in
304
- List. filter_map
311
+ List. iter
305
312
(function
306
313
| 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) ( )
309
316
| 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) ( )
312
319
| 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) ( )
315
322
| 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) ( )
318
325
| 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) ( )
321
328
| 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 []
327
335
328
336
(* Add definition source info from the [loc_to_id] table *)
329
337
let add_definitions loc_to_id occurrences =
0 commit comments