From f7444b3c0afc42c082843fd18946d411b1dca08e Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 20 Jan 2024 22:43:26 -0300 Subject: [PATCH 1/2] docstring for nested submodules --- tools/src/tools.ml | 15 +++++++++++++-- tools/tests/src/ModC.res | 6 ++++++ tools/tests/src/ModC.resi | 6 ++++++ tools/tests/src/expected/ModC.res.json | 20 ++++++++++++++++++++ tools/tests/src/expected/ModC.resi.json | 20 ++++++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tools/tests/src/ModC.res create mode 100644 tools/tests/src/ModC.resi create mode 100644 tools/tests/src/expected/ModC.res.json create mode 100644 tools/tests/src/expected/ModC.resi.json 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": [] + }] + }] +} From c4dbdc993b248bd76df24c023d61a9fbe81a8b12 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 20 Jan 2024 23:09:51 -0300 Subject: [PATCH 2/2] update CHANGELOG.md --- tools/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) 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