@@ -13,13 +13,6 @@ type constructorDoc = {
13
13
deprecated : string option ;
14
14
}
15
15
16
- type docsForModuleAlias = {
17
- id : string ;
18
- docstring : string list ;
19
- name : string ;
20
- signature : string ;
21
- }
22
-
23
16
type docItemDetail =
24
17
| Record of {fieldDocs : fieldDoc list }
25
18
| Variant of {constructorDocs : constructorDoc list }
@@ -41,7 +34,12 @@ type docItem =
41
34
(* * Additional documentation for constructors and record fields, if available. *)
42
35
}
43
36
| Module of docsForModule
44
- | ModuleAlias of docsForModuleAlias
37
+ | ModuleAlias of {
38
+ id : string ;
39
+ docstring : string list ;
40
+ name : string ;
41
+ items : docItem list ;
42
+ }
45
43
and docsForModule = {
46
44
id : string ;
47
45
docstring : string list ;
@@ -72,13 +70,13 @@ let stringifyDetail ?(indentation = 0) (detail : docItemDetail) =
72
70
stringifyObject ~start OnNewline:true ~indentation
73
71
[
74
72
(" kind" , Some (wrapInQuotes " record" ));
75
- ( " fieldDocs " ,
73
+ ( " items " ,
76
74
Some
77
75
(fieldDocs
78
76
|> List. map (fun fieldDoc ->
79
77
stringifyObject ~indentation: (indentation + 1 )
80
78
[
81
- (" fieldName " , Some (wrapInQuotes fieldDoc.fieldName));
79
+ (" name " , Some (wrapInQuotes fieldDoc.fieldName));
82
80
( " deprecated" ,
83
81
match fieldDoc.deprecated with
84
82
| Some d -> Some (wrapInQuotes d)
@@ -94,14 +92,14 @@ let stringifyDetail ?(indentation = 0) (detail : docItemDetail) =
94
92
stringifyObject ~start OnNewline:true ~indentation
95
93
[
96
94
(" kind" , Some (wrapInQuotes " variant" ));
97
- ( " constructorDocs " ,
95
+ ( " items " ,
98
96
Some
99
97
(constructorDocs
100
98
|> List. map (fun constructorDoc ->
101
99
stringifyObject ~start OnNewline:true
102
100
~indentation: (indentation + 1 )
103
101
[
104
- ( " constructorName " ,
102
+ ( " name " ,
105
103
Some (wrapInQuotes constructorDoc.constructorName) );
106
104
( " deprecated" ,
107
105
match constructorDoc.deprecated with
@@ -170,7 +168,12 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
170
168
(" kind" , Some (wrapInQuotes " moduleAlias" ));
171
169
(" name" , Some (wrapInQuotes m.name));
172
170
(" docstrings" , Some (stringifyDocstrings m.docstring));
173
- (" signature" , Some (m.signature |> Json. escape |> wrapInQuotes));
171
+ ( " items" ,
172
+ Some
173
+ (m.items
174
+ |> List. map
175
+ (stringifyDocItem ~original Env ~indentation: (indentation + 1 ))
176
+ |> array ) );
174
177
]
175
178
176
179
and stringifyDocsForModule ?(indentation = 0 ) ~originalEnv (d : docsForModule ) =
@@ -225,8 +228,6 @@ let typeDetail typ ~env ~full =
225
228
})
226
229
| _ -> None
227
230
228
- exception Invalid_file_type
229
-
230
231
let makeId modulePath ~identifier =
231
232
identifier :: modulePath |> List. rev |> SharedTypes. ident
232
233
@@ -235,7 +236,10 @@ let extractDocs ~path ~debug =
235
236
if
236
237
FindFiles. isImplementation path = false
237
238
&& FindFiles. isInterface path = false
238
- then raise Invalid_file_type ;
239
+ then (
240
+ Printf. printf " error: failed to read %s, expected an .res or .resi file\n "
241
+ path;
242
+ exit 1 );
239
243
let path =
240
244
if FindFiles. isImplementation path then
241
245
let pathAsResi =
@@ -251,7 +255,10 @@ let extractDocs ~path ~debug =
251
255
else path
252
256
in
253
257
match Cmt. loadFullCmtFromPath ~path with
254
- | None -> ()
258
+ | None ->
259
+ Printf. printf
260
+ " error: failed to generate doc for %s, try to build the project\n " path;
261
+ exit 1
255
262
| Some full ->
256
263
let file = full.file in
257
264
let structure = file.structure in
@@ -260,7 +267,7 @@ let extractDocs ~path ~debug =
260
267
let rec extractDocsForModule ?(modulePath = [env.file.moduleName])
261
268
(structure : Module.structure ) =
262
269
{
263
- id = modulePath |> ident;
270
+ id = modulePath |> List. rev |> ident;
264
271
docstring = structure.docstring |> List. map String. trim;
265
272
name = structure.name;
266
273
deprecated = structure.deprecated;
@@ -297,15 +304,27 @@ let extractDocs ~path ~debug =
297
304
| Module (Ident p ) ->
298
305
(* module Whatever = OtherModule *)
299
306
let aliasToModule = p |> pathIdentToString in
300
- let modulePath = aliasToModule :: modulePath in
307
+ let id =
308
+ (modulePath |> List. rev |> List. hd) ^ " ." ^ item.name
309
+ in
310
+ let items =
311
+ match
312
+ ProcessCmt. fileForModule ~package: full.package
313
+ aliasToModule
314
+ with
315
+ | None -> []
316
+ | Some file ->
317
+ let docs =
318
+ extractDocsForModule ~module Path:[id] file.structure
319
+ in
320
+ docs.items
321
+ in
301
322
Some
302
323
(ModuleAlias
303
324
{
304
- id = modulePath |> List. rev |> SharedTypes. ident;
305
- signature =
306
- Printf. sprintf " module %s = %s" item.name
307
- aliasToModule;
325
+ id;
308
326
name = item.name;
327
+ items;
309
328
docstring = item.docstring |> List. map String. trim;
310
329
})
311
330
| Module (Structure m ) ->
0 commit comments