diff --git a/tools/CHANGELOG.md b/tools/CHANGELOG.md index 473aec331..a7ab7a4c7 100644 --- a/tools/CHANGELOG.md +++ b/tools/CHANGELOG.md @@ -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 diff --git a/tools/src/tools.ml b/tools/src/tools.ml index d0996ca77..55e18ffa2 100644 --- a/tools/src/tools.ml +++ b/tools/src/tools.ml @@ -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 @@ -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: { } = { }. Prefer the interface. *) diff --git a/tools/tests/src/ModC.res b/tools/tests/src/ModC.res new file mode 100644 index 000000000..3c6892919 --- /dev/null +++ b/tools/tests/src/ModC.res @@ -0,0 +1,6 @@ +/** +User Module +*/ +module User = { + let name = "ReScript" +} diff --git a/tools/tests/src/ModC.resi b/tools/tests/src/ModC.resi new file mode 100644 index 000000000..c113149b4 --- /dev/null +++ b/tools/tests/src/ModC.resi @@ -0,0 +1,6 @@ +/** +User Module from interface file +*/ +module User: { + let name: string +} diff --git a/tools/tests/src/expected/ModC.res.json b/tools/tests/src/expected/ModC.res.json new file mode 100644 index 000000000..d6afb7a69 --- /dev/null +++ b/tools/tests/src/expected/ModC.res.json @@ -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": [] + }] + }] +} diff --git a/tools/tests/src/expected/ModC.resi.json b/tools/tests/src/expected/ModC.resi.json new file mode 100644 index 000000000..d6afb7a69 --- /dev/null +++ b/tools/tests/src/expected/ModC.resi.json @@ -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": [] + }] + }] +}