Skip to content

tools: docstring for nested submodules #897

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 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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": []
}]
}]
}