Skip to content

Commit 1e76109

Browse files
committed
Fix wrong id being given to doc comments
Standalone documentation comments currently do not have an id. This id was carried as the accumulator of the field, which yielded wrong results! Signed-off-by: Paul-Elliot <peada@free.fr>
1 parent 9624fc1 commit 1e76109

File tree

6 files changed

+138
-98
lines changed

6 files changed

+138
-98
lines changed

src/model/fold.ml

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,28 @@ type item =
1111
| Class of Class.t
1212
| Extension of Extension.t
1313
| ModuleType of ModuleType.t
14-
| Doc of Comment.docs_or_stop
14+
| Doc of Paths.Identifier.LabelParent.t * Comment.docs_or_stop
1515

1616
let rec unit ~f acc u =
1717
let acc = f acc (CompilationUnit u) in
18-
match u.content with Module m -> signature ~f acc m | Pack _ -> acc
18+
match u.content with
19+
| Module m -> signature ~f (u.id :> Paths.Identifier.LabelParent.t) acc m
20+
| Pack _ -> acc
1921

2022
and page ~f acc p =
2123
let open Page in
22-
docs ~f acc (`Docs p.content)
24+
docs ~f (p.name :> Paths.Identifier.LabelParent.t) acc (`Docs p.content)
2325

24-
and signature ~f acc (s : Signature.t) =
25-
List.fold_left (signature_item ~f) acc s.items
26+
and signature ~f id acc (s : Signature.t) =
27+
List.fold_left
28+
(signature_item ~f (id :> Paths.Identifier.LabelParent.t))
29+
acc s.items
2630

27-
and signature_item ~f acc s_item =
31+
and signature_item ~f id acc s_item =
2832
match s_item with
29-
| Module (_, m) -> module_ ~f acc m
30-
| ModuleType mt -> module_type ~f acc mt
33+
| Module (_, m) -> module_ ~f (m.id :> Paths.Identifier.LabelParent.t) acc m
34+
| ModuleType mt ->
35+
module_type ~f (mt.id :> Paths.Identifier.LabelParent.t) acc mt
3136
| ModuleSubstitution _ -> acc
3237
| ModuleTypeSubstitution _ -> acc
3338
| Open _ -> acc
@@ -36,43 +41,46 @@ and signature_item ~f acc s_item =
3641
| TypExt te -> type_extension ~f acc te
3742
| Exception exc -> exception_ ~f acc exc
3843
| Value v -> value ~f acc v
39-
| Class (_, cl) -> class_ ~f acc cl
40-
| ClassType (_, clt) -> class_type ~f acc clt
41-
| Include i -> include_ ~f acc i
42-
| Comment d -> docs ~f acc d
44+
| Class (_, cl) -> class_ ~f (cl.id :> Paths.Identifier.LabelParent.t) acc cl
45+
| ClassType (_, clt) ->
46+
class_type ~f (clt.id :> Paths.Identifier.LabelParent.t) acc clt
47+
| Include i -> include_ ~f id acc i
48+
| Comment d -> docs ~f id acc d
4349

44-
and docs ~f acc d = f acc (Doc d)
50+
and docs ~f id acc d = f acc (Doc (id, d))
4551

46-
and include_ ~f acc inc = signature ~f acc inc.expansion.content
52+
and include_ ~f id acc inc = signature ~f id acc inc.expansion.content
4753

48-
and class_type ~f acc ct =
54+
and class_type ~f id acc ct =
4955
(* This check is important because [is_internal] does not work on children of
5056
internal items. This means that if [Fold] did not make this check here,
5157
it would be difficult to filter for internal items afterwards. This also
5258
applies to the same check in functions bellow. *)
5359
if Paths.Identifier.is_internal ct.id then acc
5460
else
5561
let acc = f acc (ClassType ct) in
56-
match ct.expansion with None -> acc | Some cs -> class_signature ~f acc cs
62+
match ct.expansion with
63+
| None -> acc
64+
| Some cs -> class_signature ~f id acc cs
5765

58-
and class_signature ~f acc ct_expr =
59-
List.fold_left (class_signature_item ~f) acc ct_expr.items
66+
and class_signature ~f id acc ct_expr =
67+
List.fold_left (class_signature_item ~f id) acc ct_expr.items
6068

61-
and class_signature_item ~f acc item =
69+
and class_signature_item ~f id acc item =
6270
match item with
6371
| Method m -> f acc (Method m)
6472
| InstanceVariable _ -> acc
6573
| Constraint _ -> acc
6674
| Inherit _ -> acc
67-
| Comment d -> docs ~f acc d
75+
| Comment d -> docs ~f id acc d
6876

69-
and class_ ~f acc cl =
77+
and class_ ~f id acc cl =
7078
if Paths.Identifier.is_internal cl.id then acc
7179
else
7280
let acc = f acc (Class cl) in
7381
match cl.expansion with
7482
| None -> acc
75-
| Some cl_signature -> class_signature ~f acc cl_signature
83+
| Some cl_signature -> class_signature ~f id acc cl_signature
7684

7785
and exception_ ~f acc exc =
7886
if Paths.Identifier.is_internal exc.id then acc else f acc (Exception exc)
@@ -82,45 +90,48 @@ and type_extension ~f acc te = f acc (Extension te)
8290
and value ~f acc v =
8391
if Paths.Identifier.is_internal v.id then acc else f acc (Value v)
8492

85-
and module_ ~f acc m =
93+
and module_ ~f id acc m =
8694
if Paths.Identifier.is_internal m.id then acc
8795
else
8896
let acc = f acc (Module m) in
8997
match m.type_ with
9098
| Alias (_, None) -> acc
91-
| Alias (_, Some s_e) -> simple_expansion ~f acc s_e
92-
| ModuleType mte -> module_type_expr ~f acc mte
99+
| Alias (_, Some s_e) -> simple_expansion ~f id acc s_e
100+
| ModuleType mte -> module_type_expr ~f id acc mte
93101

94102
and type_decl ~f acc td =
95103
if Paths.Identifier.is_internal td.id then acc else f acc (TypeDecl td)
96104

97-
and module_type ~f acc mt =
105+
and module_type ~f id acc mt =
98106
if Paths.Identifier.is_internal mt.id then acc
99107
else
100108
let acc = f acc (ModuleType mt) in
101109
match mt.expr with
102110
| None -> acc
103-
| Some mt_expr -> module_type_expr ~f acc mt_expr
111+
| Some mt_expr -> module_type_expr ~f id acc mt_expr
104112

105-
and simple_expansion ~f acc s_e =
113+
and simple_expansion ~f id acc s_e =
106114
match s_e with
107-
| Signature sg -> signature ~f acc sg
115+
| Signature sg -> signature ~f id acc sg
108116
| Functor (p, s_e) ->
109117
let acc = functor_parameter ~f acc p in
110-
simple_expansion ~f acc s_e
118+
simple_expansion ~f id acc s_e
111119

112-
and module_type_expr ~f acc mte =
120+
and module_type_expr ~f id acc mte =
113121
match mte with
114-
| Signature s -> signature ~f acc s
122+
| Signature s -> signature ~f id acc s
115123
| Functor (fp, mt_expr) ->
116124
let acc = functor_parameter ~f acc fp in
117-
module_type_expr ~f acc mt_expr
118-
| With { w_expansion = Some sg; _ } -> simple_expansion ~f acc sg
119-
| TypeOf { t_expansion = Some sg; _ } -> simple_expansion ~f acc sg
120-
| Path { p_expansion = Some sg; _ } -> simple_expansion ~f acc sg
125+
module_type_expr ~f id acc mt_expr
126+
| With { w_expansion = Some sg; _ } -> simple_expansion ~f id acc sg
127+
| TypeOf { t_expansion = Some sg; _ } -> simple_expansion ~f id acc sg
128+
| Path { p_expansion = Some sg; _ } -> simple_expansion ~f id acc sg
121129
| Path { p_expansion = None; _ } -> acc
122130
| With { w_expansion = None; _ } -> acc
123131
| TypeOf { t_expansion = None; _ } -> acc
124132

125133
and functor_parameter ~f acc fp =
126-
match fp with Unit -> acc | Named n -> module_type_expr ~f acc n.expr
134+
match fp with
135+
| Unit -> acc
136+
| Named n ->
137+
module_type_expr ~f (n.id :> Paths.Identifier.LabelParent.t) acc n.expr

src/model/fold.mli

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,83 @@ type item =
1717
| Class of Class.t
1818
| Extension of Extension.t
1919
| ModuleType of ModuleType.t
20-
| Doc of Comment.docs_or_stop
20+
| Doc of Paths.Identifier.LabelParent.t * Comment.docs_or_stop
2121

22-
(** Bellow are the folding functions. For items that may contain
22+
(** Below are the folding functions. For items that may contain
2323
others, such as [signature], it folds recursively on the
24-
sub-items. It does not recurse into internal items. *)
24+
sub-items. It does not recurse into internal items.
25+
26+
The LabelParent identifier is used to give an id to the doc entries. *)
2527

2628
val unit : f:('a -> item -> 'a) -> 'a -> Compilation_unit.t -> 'a
2729
val page : f:('a -> item -> 'a) -> 'a -> Page.t -> 'a
2830

29-
val signature : f:('a -> item -> 'a) -> 'a -> Signature.t -> 'a
30-
val signature_item : f:('a -> item -> 'a) -> 'a -> Signature.item -> 'a
31-
val docs : f:('a -> item -> 'a) -> 'a -> Comment.docs_or_stop -> 'a
32-
val include_ : f:('a -> item -> 'a) -> 'a -> Include.t -> 'a
33-
val class_type : f:('a -> item -> 'a) -> 'a -> ClassType.t -> 'a
34-
val class_signature : f:('a -> item -> 'a) -> 'a -> ClassSignature.t -> 'a
31+
val signature :
32+
f:('a -> item -> 'a) ->
33+
Paths.Identifier.LabelParent.t ->
34+
'a ->
35+
Signature.t ->
36+
'a
37+
val signature_item :
38+
f:('a -> item -> 'a) ->
39+
Paths.Identifier.LabelParent.t ->
40+
'a ->
41+
Signature.item ->
42+
'a
43+
val docs :
44+
f:('a -> item -> 'a) ->
45+
Paths.Identifier.LabelParent.t ->
46+
'a ->
47+
Comment.docs_or_stop ->
48+
'a
49+
val include_ :
50+
f:('a -> item -> 'a) ->
51+
Paths.Identifier.LabelParent.t ->
52+
'a ->
53+
Include.t ->
54+
'a
55+
val class_type :
56+
f:('a -> item -> 'a) ->
57+
Paths.Identifier.LabelParent.t ->
58+
'a ->
59+
ClassType.t ->
60+
'a
61+
val class_signature :
62+
f:('a -> item -> 'a) ->
63+
Paths.Identifier.LabelParent.t ->
64+
'a ->
65+
ClassSignature.t ->
66+
'a
3567
val class_signature_item :
36-
f:('a -> item -> 'a) -> 'a -> ClassSignature.item -> 'a
37-
val class_ : f:('a -> item -> 'a) -> 'a -> Class.t -> 'a
68+
f:('a -> item -> 'a) ->
69+
Paths.Identifier.LabelParent.t ->
70+
'a ->
71+
ClassSignature.item ->
72+
'a
73+
val class_ :
74+
f:('a -> item -> 'a) -> Paths.Identifier.LabelParent.t -> 'a -> Class.t -> 'a
3875
val exception_ : f:('a -> item -> 'a) -> 'a -> Exception.t -> 'a
3976
val type_extension : f:('a -> item -> 'a) -> 'a -> Extension.t -> 'a
4077
val value : f:('a -> item -> 'a) -> 'a -> Value.t -> 'a
41-
val module_ : f:('a -> item -> 'a) -> 'a -> Module.t -> 'a
78+
val module_ :
79+
f:('a -> item -> 'a) -> Paths.Identifier.LabelParent.t -> 'a -> Module.t -> 'a
4280
val type_decl : f:('a -> item -> 'a) -> 'a -> TypeDecl.t -> 'a
43-
val module_type : f:('a -> item -> 'a) -> 'a -> ModuleType.t -> 'a
81+
val module_type :
82+
f:('a -> item -> 'a) ->
83+
Paths.Identifier.LabelParent.t ->
84+
'a ->
85+
ModuleType.t ->
86+
'a
4487
val simple_expansion :
45-
f:('a -> item -> 'a) -> 'a -> ModuleType.simple_expansion -> 'a
46-
val module_type_expr : f:('a -> item -> 'a) -> 'a -> ModuleType.expr -> 'a
88+
f:('a -> item -> 'a) ->
89+
Paths.Identifier.LabelParent.t ->
90+
'a ->
91+
ModuleType.simple_expansion ->
92+
'a
93+
val module_type_expr :
94+
f:('a -> item -> 'a) ->
95+
Paths.Identifier.LabelParent.t ->
96+
'a ->
97+
ModuleType.expr ->
98+
'a
4799
val functor_parameter : f:('a -> item -> 'a) -> 'a -> FunctorParameter.t -> 'a

src/search/entry.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ and entries_of_doc id d =
146146
| `Math_block _ -> [ entry ~id ~doc:[ d ] ~kind:(Doc MathBlock) ]
147147
| `Table _ -> []
148148

149-
let entries_of_item id (x : Odoc_model.Fold.item) =
149+
let entries_of_item (x : Odoc_model.Fold.item) =
150150
match x with
151151
| CompilationUnit u -> (
152152
match u.content with
@@ -219,5 +219,5 @@ let entries_of_item id (x : Odoc_model.Fold.item) =
219219
(entry_of_extension_constructor te.type_path te.type_params)
220220
te.constructors)
221221
| ModuleType mt -> [ entry ~id:mt.id ~doc:mt.doc ~kind:ModuleType ]
222-
| Doc `Stop -> []
223-
| Doc (`Docs d) -> entries_of_docs id d
222+
| Doc (_, `Stop) -> []
223+
| Doc (id, `Docs d) -> entries_of_docs id d

src/search/entry.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,4 @@ type t = {
6161
kind : kind;
6262
}
6363

64-
val entries_of_item :
65-
Odoc_model.Paths.Identifier.Any.t -> Odoc_model.Fold.item -> t list
64+
val entries_of_item : Odoc_model.Fold.item -> t list

src/search/json_index/json_search.ml

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -193,42 +193,20 @@ let output_json ppf first entries =
193193
first entries
194194

195195
let unit ppf u =
196-
let f (first, id) i =
197-
let entries = Entry.entries_of_item id i in
196+
let f first i =
197+
let entries = Entry.entries_of_item i in
198198
let entries =
199199
List.map (fun entry -> (entry, Html.of_entry entry)) entries
200200
in
201-
let id =
202-
match i with
203-
| CompilationUnit u -> (u.id :> Odoc_model.Paths.Identifier.t)
204-
| TypeDecl _ -> id
205-
| Module m -> (m.id :> Odoc_model.Paths.Identifier.t)
206-
| Value _ -> id
207-
| Exception _ -> id
208-
| ClassType ct -> (ct.id :> Odoc_model.Paths.Identifier.t)
209-
| Method _ -> id
210-
| Class c -> (c.id :> Odoc_model.Paths.Identifier.t)
211-
| Extension _ -> id
212-
| ModuleType mt -> (mt.id :> Odoc_model.Paths.Identifier.t)
213-
| Doc _ -> id
214-
in
215201
let first = output_json ppf first entries in
216-
(first, id)
217-
in
218-
let _first =
219-
Odoc_model.Fold.unit ~f
220-
( true,
221-
(u.Odoc_model.Lang.Compilation_unit.id :> Odoc_model.Paths.Identifier.t)
222-
)
223-
u
202+
first
224203
in
204+
let _first = Odoc_model.Fold.unit ~f true u in
225205
()
226206

227207
let page ppf (page : Odoc_model.Lang.Page.t) =
228208
let f first i =
229-
let entries =
230-
Entry.entries_of_item (page.name :> Odoc_model.Paths.Identifier.t) i
231-
in
209+
let entries = Entry.entries_of_item i in
232210
let entries =
233211
List.map (fun entry -> (entry, Html.of_entry entry)) entries
234212
in

0 commit comments

Comments
 (0)