Skip to content

Commit

Permalink
tools: docstring for nested submodules (#897)
Browse files Browse the repository at this point in the history
* docstring for nested submodules

* update CHANGELOG.md
  • Loading branch information
aspeddro authored Jan 22, 2024
1 parent 9b6e384 commit a9e1e18
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
## master

#### :bug: Bug Fix

- Print docstrings for nested submodules. https://github.com/rescript-lang/rescript-vscode/pull/897
- Print `deprecated` field for module. https://github.com/rescript-lang/rescript-vscode/pull/897

## 0.4.0

#### :bug: Bug Fix
Expand Down
15 changes: 13 additions & 2 deletions tools/src/tools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
("id", Some (wrapInQuotes m.id));
("name", Some (wrapInQuotes m.name));
("kind", Some (wrapInQuotes "module"));
( "deprecated",
match m.deprecated with
| Some d -> Some (wrapInQuotes d)
| None -> None );
("docstrings", Some (stringifyDocstrings m.docstring));
( "items",
Some
Expand Down Expand Up @@ -353,10 +357,17 @@ let extractDocs ~path ~debug =
})
| Module (Structure m) ->
(* module Whatever = {} in res or module Whatever: {} in resi. *)
let modulePath = m.name :: modulePath in
let docs = extractDocsForModule ~modulePath m in
Some
(Module
(extractDocsForModule
~modulePath:(m.name :: modulePath) m))
{
id = modulePath |> List.rev |> ident;
name = m.name;
docstring = item.docstring @ m.docstring;
deprecated = item.deprecated;
items = docs.items;
})
| Module
(Constraint (Structure _impl, Structure interface)) ->
(* module Whatever: { <interface> } = { <impl> }. Prefer the interface. *)
Expand Down
6 changes: 6 additions & 0 deletions tools/tests/src/ModC.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
User Module
*/
module User = {
let name = "ReScript"
}
6 changes: 6 additions & 0 deletions tools/tests/src/ModC.resi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
User Module from interface file
*/
module User: {
let name: string
}
20 changes: 20 additions & 0 deletions tools/tests/src/expected/ModC.res.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

{
"name": "ModC",
"docstrings": [],
"items": [
{
"id": "ModC.User",
"name": "User",
"kind": "module",
"docstrings": ["User Module from interface file"],
"items": [
{
"id": "ModC.User.name",
"kind": "value",
"name": "name",
"signature": "let name: string",
"docstrings": []
}]
}]
}
20 changes: 20 additions & 0 deletions tools/tests/src/expected/ModC.resi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

{
"name": "ModC",
"docstrings": [],
"items": [
{
"id": "ModC.User",
"name": "User",
"kind": "module",
"docstrings": ["User Module from interface file"],
"items": [
{
"id": "ModC.User.name",
"kind": "value",
"name": "name",
"signature": "let name: string",
"docstrings": []
}]
}]
}

0 comments on commit a9e1e18

Please sign in to comment.