@@ -44,6 +44,7 @@ type docItem =
4444 (* * Additional documentation for constructors and record fields, if available. *)
4545 }
4646 | Module of docsForModule
47+ | ModuleType of docsForModule
4748 | ModuleAlias of {
4849 id : string ;
4950 docstring : string list ;
@@ -204,6 +205,26 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
204205 (stringifyDocItem ~original Env ~indentation: (indentation + 1 ))
205206 |> array ) );
206207 ]
208+ | ModuleType m ->
209+ stringifyObject ~start OnNewline:true ~indentation
210+ [
211+ (" id" , Some (wrapInQuotes m.id));
212+ (" name" , Some (wrapInQuotes m.name));
213+ (" kind" , Some (wrapInQuotes " moduleType" ));
214+ ( " deprecated" ,
215+ match m.deprecated with
216+ | Some d -> Some (wrapInQuotes d)
217+ | None -> None );
218+ (" docstrings" , Some (stringifyDocstrings m.docstring));
219+ ( " source" ,
220+ Some (stringifySource ~indentation: (indentation + 1 ) m.source) );
221+ ( " items" ,
222+ Some
223+ (m.items
224+ |> List. map
225+ (stringifyDocItem ~original Env ~indentation: (indentation + 1 ))
226+ |> array ) );
227+ ]
207228 | ModuleAlias m ->
208229 stringifyObject ~start OnNewline:true ~indentation
209230 [
@@ -379,7 +400,7 @@ let extractDocs ~entryPointFile ~debug =
379400 detail = typeDetail typ ~full ~env ;
380401 source;
381402 })
382- | Module ( Ident p ) ->
403+ | Module { type_ = Ident p ; isModuleType = false } ->
383404 (* module Whatever = OtherModule *)
384405 let aliasToModule = p |> pathIdentToString in
385406 let id =
@@ -409,7 +430,7 @@ let extractDocs ~entryPointFile ~debug =
409430 item.docstring @ internalDocstrings
410431 |> List. map String. trim;
411432 })
412- | Module ( Structure m ) ->
433+ | Module { type_ = Structure m ; isModuleType = false } ->
413434 (* module Whatever = {} in res or module Whatever: {} in resi. *)
414435 let modulePath = m.name :: modulePath in
415436 let docs = extractDocsForModule ~module Path m in
@@ -423,8 +444,25 @@ let extractDocs ~entryPointFile ~debug =
423444 source;
424445 items = docs.items;
425446 })
447+ | Module {type_ = Structure m ; isModuleType = true } ->
448+ (* module type Whatever = {} *)
449+ let modulePath = m.name :: modulePath in
450+ let docs = extractDocsForModule ~module Path m in
451+ Some
452+ (ModuleType
453+ {
454+ id = modulePath |> List. rev |> ident;
455+ name = m.name;
456+ docstring = item.docstring @ m.docstring;
457+ deprecated = item.deprecated;
458+ source;
459+ items = docs.items;
460+ })
426461 | Module
427- (Constraint (Structure _impl, Structure interface)) ->
462+ {
463+ type_ =
464+ Constraint (Structure _impl, Structure interface);
465+ } ->
428466 (* module Whatever: { <interface> } = { <impl> }. Prefer the interface. *)
429467 Some
430468 (Module
0 commit comments