Skip to content

Commit a9e1e18

Browse files
authored
tools: docstring for nested submodules (#897)
* docstring for nested submodules * update CHANGELOG.md
1 parent 9b6e384 commit a9e1e18

File tree

6 files changed

+70
-2
lines changed

6 files changed

+70
-2
lines changed

tools/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
1313
## master
1414

15+
#### :bug: Bug Fix
16+
17+
- Print docstrings for nested submodules. https://github.com/rescript-lang/rescript-vscode/pull/897
18+
- Print `deprecated` field for module. https://github.com/rescript-lang/rescript-vscode/pull/897
19+
1520
## 0.4.0
1621

1722
#### :bug: Bug Fix

tools/src/tools.ml

+13-2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
172172
("id", Some (wrapInQuotes m.id));
173173
("name", Some (wrapInQuotes m.name));
174174
("kind", Some (wrapInQuotes "module"));
175+
( "deprecated",
176+
match m.deprecated with
177+
| Some d -> Some (wrapInQuotes d)
178+
| None -> None );
175179
("docstrings", Some (stringifyDocstrings m.docstring));
176180
( "items",
177181
Some
@@ -353,10 +357,17 @@ let extractDocs ~path ~debug =
353357
})
354358
| Module (Structure m) ->
355359
(* module Whatever = {} in res or module Whatever: {} in resi. *)
360+
let modulePath = m.name :: modulePath in
361+
let docs = extractDocsForModule ~modulePath m in
356362
Some
357363
(Module
358-
(extractDocsForModule
359-
~modulePath:(m.name :: modulePath) m))
364+
{
365+
id = modulePath |> List.rev |> ident;
366+
name = m.name;
367+
docstring = item.docstring @ m.docstring;
368+
deprecated = item.deprecated;
369+
items = docs.items;
370+
})
360371
| Module
361372
(Constraint (Structure _impl, Structure interface)) ->
362373
(* module Whatever: { <interface> } = { <impl> }. Prefer the interface. *)

tools/tests/src/ModC.res

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
User Module
3+
*/
4+
module User = {
5+
let name = "ReScript"
6+
}

tools/tests/src/ModC.resi

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
User Module from interface file
3+
*/
4+
module User: {
5+
let name: string
6+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
{
3+
"name": "ModC",
4+
"docstrings": [],
5+
"items": [
6+
{
7+
"id": "ModC.User",
8+
"name": "User",
9+
"kind": "module",
10+
"docstrings": ["User Module from interface file"],
11+
"items": [
12+
{
13+
"id": "ModC.User.name",
14+
"kind": "value",
15+
"name": "name",
16+
"signature": "let name: string",
17+
"docstrings": []
18+
}]
19+
}]
20+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
{
3+
"name": "ModC",
4+
"docstrings": [],
5+
"items": [
6+
{
7+
"id": "ModC.User",
8+
"name": "User",
9+
"kind": "module",
10+
"docstrings": ["User Module from interface file"],
11+
"items": [
12+
{
13+
"id": "ModC.User.name",
14+
"kind": "value",
15+
"name": "name",
16+
"signature": "let name: string",
17+
"docstrings": []
18+
}]
19+
}]
20+
}

0 commit comments

Comments
 (0)