Skip to content

add moduletypeid field for modules with explicitly annotated module type #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions tools/src/tools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ type docItem =
(** Additional documentation for constructors and record fields, if available. *)
}
| Module of docsForModule
| ModuleType of docsForModule
| ModuleType of {
id: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you update the rescript types accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring: string list;
deprecated: string option;
name: string;
source: source;
items: docItem list;
}
| ModuleAlias of {
id: string;
docstring: string list;
Expand All @@ -57,6 +64,7 @@ and docsForModule = {
docstring: string list;
deprecated: string option;
name: string;
moduletype: string option;
source: source;
items: docItem list;
}
Expand Down Expand Up @@ -195,6 +203,10 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
match m.deprecated with
| Some d -> Some (wrapInQuotes d)
| None -> None );
( "moduletype",
match m.moduletype with
| Some path -> Some (wrapInQuotes path)
| None -> None );
("docstrings", Some (stringifyDocstrings m.docstring));
( "source",
Some (stringifySource ~indentation:(indentation + 1) m.source) );
Expand Down Expand Up @@ -356,6 +368,7 @@ let extractDocs ~entryPointFile ~debug =
id = modulePath |> List.rev |> ident;
docstring = structure.docstring |> List.map String.trim;
name = structure.name;
moduletype = None;
deprecated = structure.deprecated;
source =
{
Expand Down Expand Up @@ -439,6 +452,7 @@ let extractDocs ~entryPointFile ~debug =
{
id = modulePath |> List.rev |> ident;
name = m.name;
moduletype = None;
docstring = item.docstring @ m.docstring;
deprecated = item.deprecated;
source;
Expand Down Expand Up @@ -469,12 +483,13 @@ let extractDocs ~entryPointFile ~debug =
(extractDocsForModule
~modulePath:(interface.name :: modulePath)
interface))
| Module {type_ = Constraint (Structure m, Ident _)} ->
(* module M: T = { }. Print M *)
Some
(Module
(extractDocsForModule
~modulePath:(m.name :: modulePath) m))
| Module {type_ = Constraint (Structure m, Ident p)} ->
(* module M: T = { <impl> }. Print M *)
let docs =
extractDocsForModule ~modulePath:(m.name :: modulePath)
m
in
Some (Module {docs with moduletype = Some (Path.name p)})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same string, which is used for the id of the module type, when generating json for the module type?

For further processing it would make sense, to use the id. If so, the record field should probably renamed as well (moduleTypeId).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed field to moduletypeid bc all fields are in lowercase.

a67efa5 added full id DocExtractionRes.Example

| _ -> None);
}
in
Expand Down
1 change: 1 addition & 0 deletions tools/tests/src/expected/DocExtractionRes.res.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
"id": "DocExtractionRes.M",
"name": "M",
"kind": "module",
"moduletype": "Example",
"docstrings": ["implementation of Example module type"],
"source": {
"filepath": "src/DocExtractionRes.res",
Expand Down