Skip to content

Commit 0114650

Browse files
committed
add moduletype field for modules with explicitly
annotated module type
1 parent 0a631e1 commit 0114650

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

tools/src/tools.ml

+22-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ type docItem =
4444
(** Additional documentation for constructors and record fields, if available. *)
4545
}
4646
| Module of docsForModule
47-
| ModuleType of docsForModule
47+
| ModuleType of {
48+
id: string;
49+
docstring: string list;
50+
deprecated: string option;
51+
name: string;
52+
source: source;
53+
items: docItem list;
54+
}
4855
| ModuleAlias of {
4956
id: string;
5057
docstring: string list;
@@ -57,6 +64,7 @@ and docsForModule = {
5764
docstring: string list;
5865
deprecated: string option;
5966
name: string;
67+
moduletype: string option;
6068
source: source;
6169
items: docItem list;
6270
}
@@ -195,6 +203,10 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
195203
match m.deprecated with
196204
| Some d -> Some (wrapInQuotes d)
197205
| None -> None );
206+
( "moduletype",
207+
match m.moduletype with
208+
| Some path -> Some (wrapInQuotes path)
209+
| None -> None );
198210
("docstrings", Some (stringifyDocstrings m.docstring));
199211
( "source",
200212
Some (stringifySource ~indentation:(indentation + 1) m.source) );
@@ -356,6 +368,7 @@ let extractDocs ~entryPointFile ~debug =
356368
id = modulePath |> List.rev |> ident;
357369
docstring = structure.docstring |> List.map String.trim;
358370
name = structure.name;
371+
moduletype = None;
359372
deprecated = structure.deprecated;
360373
source =
361374
{
@@ -439,6 +452,7 @@ let extractDocs ~entryPointFile ~debug =
439452
{
440453
id = modulePath |> List.rev |> ident;
441454
name = m.name;
455+
moduletype = None;
442456
docstring = item.docstring @ m.docstring;
443457
deprecated = item.deprecated;
444458
source;
@@ -469,12 +483,13 @@ let extractDocs ~entryPointFile ~debug =
469483
(extractDocsForModule
470484
~modulePath:(interface.name :: modulePath)
471485
interface))
472-
| Module {type_ = Constraint (Structure m, Ident _)} ->
473-
(* module M: T = { }. Print M *)
474-
Some
475-
(Module
476-
(extractDocsForModule
477-
~modulePath:(m.name :: modulePath) m))
486+
| Module {type_ = Constraint (Structure m, Ident p)} ->
487+
(* module M: T = { <impl> }. Print M *)
488+
let docs =
489+
extractDocsForModule ~modulePath:(m.name :: modulePath)
490+
m
491+
in
492+
Some (Module {docs with moduletype = Some (Path.name p)})
478493
| _ -> None);
479494
}
480495
in

tools/tests/src/expected/DocExtractionRes.res.json

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@
311311
"id": "DocExtractionRes.M",
312312
"name": "M",
313313
"kind": "module",
314+
"moduletype": "Example",
314315
"docstrings": ["implementation of Example module type"],
315316
"source": {
316317
"filepath": "src/DocExtractionRes.res",

0 commit comments

Comments
 (0)