Skip to content

Commit 58711a0

Browse files
aspeddrozth
authored andcommitted
docgen: convert items to array (#822)
1 parent 3d3aa8e commit 58711a0

File tree

4 files changed

+128
-151
lines changed

4 files changed

+128
-151
lines changed

analysis/src/DocExtraction.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
158158
("kind", Some (wrapInQuotes "module"));
159159
( "items",
160160
Some
161-
(stringifyDocsForModule ~originalEnv ~indentation:(indentation + 1)
162-
m) );
161+
(m.items
162+
|> List.map
163+
(stringifyDocItem ~originalEnv ~indentation:(indentation + 1))
164+
|> array) );
163165
]
164166
| ModuleAlias m ->
165167
stringifyObject ~startOnNewline:true ~indentation

analysis/tests/src/expected/DocExtraction2.res.txt

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,21 @@ preferring found resi file for impl: src/DocExtraction2.resi
2424
"id": "InnerModule.DocExtraction2",
2525
"name": "InnerModule",
2626
"kind": "module",
27-
"items":
27+
"items": [
2828
{
29-
"name": "InnerModule",
30-
"docstrings": [],
31-
"items": [
32-
{
33-
"id": "DocExtraction2.InnerModule.t",
34-
"kind": "type",
35-
"name": "t",
36-
"signature": "type t",
37-
"docstrings": ["This type is also t."]
38-
},
39-
{
40-
"id": "DocExtraction2.InnerModule.make",
41-
"kind": "value",
42-
"name": "make",
43-
"signature": "let make: unit => t",
44-
"docstrings": ["Maker of tea."]
45-
}]
46-
}
29+
"id": "DocExtraction2.InnerModule.t",
30+
"kind": "type",
31+
"name": "t",
32+
"signature": "type t",
33+
"docstrings": ["This type is also t."]
34+
},
35+
{
36+
"id": "DocExtraction2.InnerModule.make",
37+
"kind": "value",
38+
"name": "make",
39+
"signature": "let make: unit => t",
40+
"docstrings": ["Maker of tea."]
41+
}]
4742
}]
4843
}
4944

analysis/tests/src/expected/DocExtraction2.resi.txt

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,21 @@ extracting docs for src/DocExtraction2.resi
2323
"id": "InnerModule.DocExtraction2",
2424
"name": "InnerModule",
2525
"kind": "module",
26-
"items":
26+
"items": [
2727
{
28-
"name": "InnerModule",
29-
"docstrings": [],
30-
"items": [
31-
{
32-
"id": "DocExtraction2.InnerModule.t",
33-
"kind": "type",
34-
"name": "t",
35-
"signature": "type t",
36-
"docstrings": ["This type is also t."]
37-
},
38-
{
39-
"id": "DocExtraction2.InnerModule.make",
40-
"kind": "value",
41-
"name": "make",
42-
"signature": "let make: unit => t",
43-
"docstrings": ["Maker of tea."]
44-
}]
45-
}
28+
"id": "DocExtraction2.InnerModule.t",
29+
"kind": "type",
30+
"name": "t",
31+
"signature": "type t",
32+
"docstrings": ["This type is also t."]
33+
},
34+
{
35+
"id": "DocExtraction2.InnerModule.make",
36+
"kind": "value",
37+
"name": "make",
38+
"signature": "let make: unit => t",
39+
"docstrings": ["Maker of tea."]
40+
}]
4641
}]
4742
}
4843

analysis/tests/src/expected/DocExtractionRes.res.txt

Lines changed: 96 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -45,134 +45,119 @@ extracting docs for src/DocExtractionRes.res
4545
"id": "SomeInnerModule.DocExtractionRes",
4646
"name": "SomeInnerModule",
4747
"kind": "module",
48-
"items":
48+
"items": [
4949
{
50-
"name": "SomeInnerModule",
51-
"docstrings": ["Another module level docstring here."],
52-
"items": [
50+
"id": "DocExtractionRes.SomeInnerModule.status",
51+
"kind": "type",
52+
"name": "status",
53+
"signature": "type status = Started(t) | Stopped | Idle",
54+
"docstrings": [],
55+
"detail":
5356
{
54-
"id": "DocExtractionRes.SomeInnerModule.status",
55-
"kind": "type",
56-
"name": "status",
57-
"signature": "type status = Started(t) | Stopped | Idle",
58-
"docstrings": [],
59-
"detail":
57+
"kind": "variant",
58+
"constructorDocs": [
6059
{
61-
"kind": "variant",
62-
"constructorDocs": [
63-
{
64-
"constructorName": "Started",
65-
"docstrings": ["If this is started or not"],
66-
"signature": "Started(t)"
67-
},
68-
{
69-
"constructorName": "Stopped",
70-
"docstrings": ["Stopped?"],
71-
"signature": "Stopped"
72-
},
73-
{
74-
"constructorName": "Idle",
75-
"docstrings": ["Now idle."],
76-
"signature": "Idle"
77-
}]
78-
}
79-
},
80-
{
81-
"id": "DocExtractionRes.SomeInnerModule.validInputs",
82-
"kind": "type",
83-
"name": "validInputs",
84-
"signature": "type validInputs = [\\n | #\\\"needs-escaping\\\"\\n | #something\\n | #status(status)\\n | #withPayload(int)\\n]",
85-
"docstrings": ["These are all the valid inputs."]
86-
},
87-
{
88-
"id": "DocExtractionRes.SomeInnerModule.callback",
89-
"kind": "type",
90-
"name": "callback",
91-
"signature": "type callback = (t, ~status: status) => unit",
92-
"docstrings": []
93-
}]
94-
}
60+
"constructorName": "Started",
61+
"docstrings": ["If this is started or not"],
62+
"signature": "Started(t)"
63+
},
64+
{
65+
"constructorName": "Stopped",
66+
"docstrings": ["Stopped?"],
67+
"signature": "Stopped"
68+
},
69+
{
70+
"constructorName": "Idle",
71+
"docstrings": ["Now idle."],
72+
"signature": "Idle"
73+
}]
74+
}
75+
},
76+
{
77+
"id": "DocExtractionRes.SomeInnerModule.validInputs",
78+
"kind": "type",
79+
"name": "validInputs",
80+
"signature": "type validInputs = [\\n | #\\\"needs-escaping\\\"\\n | #something\\n | #status(status)\\n | #withPayload(int)\\n]",
81+
"docstrings": ["These are all the valid inputs."]
82+
},
83+
{
84+
"id": "DocExtractionRes.SomeInnerModule.callback",
85+
"kind": "type",
86+
"name": "callback",
87+
"signature": "type callback = (t, ~status: status) => unit",
88+
"docstrings": []
89+
}]
9590
},
9691
{
9792
"id": "AnotherModule.DocExtractionRes",
9893
"name": "AnotherModule",
9994
"kind": "module",
100-
"items":
95+
"items": [
10196
{
102-
"name": "AnotherModule",
103-
"docstrings": ["Mighty fine module here too!"],
104-
"items": [
105-
{
106-
"id": "DocExtractionRes.AnotherModule.SomeInnerModule",
107-
"kind": "moduleAlias",
108-
"name": "LinkedModule",
109-
"docstrings": ["This links another module. Neat."],
110-
"signature": "module LinkedModule = SomeInnerModule"
111-
},
112-
{
113-
"id": "DocExtractionRes.AnotherModule.callback",
114-
"kind": "type",
115-
"name": "callback",
116-
"signature": "type callback = SomeInnerModule.status => unit",
117-
"docstrings": ["Testing what this looks like."]
118-
},
119-
{
120-
"id": "DocExtractionRes.AnotherModule.isGoodStatus",
121-
"kind": "value",
122-
"name": "isGoodStatus",
123-
"signature": "let isGoodStatus: SomeInnerModule.status => bool",
124-
"docstrings": []
125-
},
97+
"id": "DocExtractionRes.AnotherModule.SomeInnerModule",
98+
"kind": "moduleAlias",
99+
"name": "LinkedModule",
100+
"docstrings": ["This links another module. Neat."],
101+
"signature": "module LinkedModule = SomeInnerModule"
102+
},
103+
{
104+
"id": "DocExtractionRes.AnotherModule.callback",
105+
"kind": "type",
106+
"name": "callback",
107+
"signature": "type callback = SomeInnerModule.status => unit",
108+
"docstrings": ["Testing what this looks like."]
109+
},
110+
{
111+
"id": "DocExtractionRes.AnotherModule.isGoodStatus",
112+
"kind": "value",
113+
"name": "isGoodStatus",
114+
"signature": "let isGoodStatus: SomeInnerModule.status => bool",
115+
"docstrings": []
116+
},
117+
{
118+
"id": "DocExtractionRes.AnotherModule.someVariantWithInlineRecords",
119+
"kind": "type",
120+
"name": "someVariantWithInlineRecords",
121+
"signature": "type someVariantWithInlineRecords = SomeStuff({offline: bool})",
122+
"docstrings": ["Trying how it looks with an inline record in a variant."],
123+
"detail":
126124
{
127-
"id": "DocExtractionRes.AnotherModule.someVariantWithInlineRecords",
128-
"kind": "type",
129-
"name": "someVariantWithInlineRecords",
130-
"signature": "type someVariantWithInlineRecords = SomeStuff({offline: bool})",
131-
"docstrings": ["Trying how it looks with an inline record in a variant."],
132-
"detail":
125+
"kind": "variant",
126+
"constructorDocs": [
133127
{
134-
"kind": "variant",
135-
"constructorDocs": [
136-
{
137-
"constructorName": "SomeStuff",
138-
"docstrings": ["This has inline records..."],
139-
"signature": "SomeStuff"
140-
}]
141-
}
142-
},
143-
{
144-
"id": "DocExtractionRes.AnotherModule.domRoot",
145-
"kind": "type",
146-
"name": "domRoot",
147-
"signature": "type domRoot = unit => ReactDOM.Client.Root.t",
148-
"docstrings": ["Callback to get the DOM root..."]
149-
}]
150-
}
128+
"constructorName": "SomeStuff",
129+
"docstrings": ["This has inline records..."],
130+
"signature": "SomeStuff"
131+
}]
132+
}
133+
},
134+
{
135+
"id": "DocExtractionRes.AnotherModule.domRoot",
136+
"kind": "type",
137+
"name": "domRoot",
138+
"signature": "type domRoot = unit => ReactDOM.Client.Root.t",
139+
"docstrings": ["Callback to get the DOM root..."]
140+
}]
151141
},
152142
{
153143
"id": "ModuleWithThingsThatShouldNotBeExported.DocExtractionRes",
154144
"name": "ModuleWithThingsThatShouldNotBeExported",
155145
"kind": "module",
156-
"items":
146+
"items": [
157147
{
158-
"name": "ModuleWithThingsThatShouldNotBeExported",
159-
"docstrings": [],
160-
"items": [
161-
{
162-
"id": "DocExtractionRes.ModuleWithThingsThatShouldNotBeExported.t",
163-
"kind": "type",
164-
"name": "t",
165-
"signature": "type t",
166-
"docstrings": ["The type t is stuff."]
167-
},
168-
{
169-
"id": "DocExtractionRes.ModuleWithThingsThatShouldNotBeExported.make",
170-
"kind": "value",
171-
"name": "make",
172-
"signature": "let make: unit => t",
173-
"docstrings": ["The maker of stuff!"]
174-
}]
175-
}
148+
"id": "DocExtractionRes.ModuleWithThingsThatShouldNotBeExported.t",
149+
"kind": "type",
150+
"name": "t",
151+
"signature": "type t",
152+
"docstrings": ["The type t is stuff."]
153+
},
154+
{
155+
"id": "DocExtractionRes.ModuleWithThingsThatShouldNotBeExported.make",
156+
"kind": "value",
157+
"name": "make",
158+
"signature": "let make: unit => t",
159+
"docstrings": ["The maker of stuff!"]
160+
}]
176161
}]
177162
}
178163

0 commit comments

Comments
 (0)