Skip to content

Commit a935b5d

Browse files
nojafcknitt
andauthored
Rescript tool tweaks (#7160)
* Use JSON.t in decodeFromJson * Add additional signature information to doc json * Update tests * Format docgen code * Revert removal of unwrap_uppercase_exotic * Update tests * Update runtime/RescriptTools_Docgen.res Co-authored-by: Christoph Knittel <[email protected]> * Fix typo in signature * Fix more typos --------- Co-authored-by: Christoph Knittel <[email protected]>
1 parent 9127794 commit a935b5d

10 files changed

+303
-4
lines changed

runtime/RescriptTools_Docgen.res

+14-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,21 @@ type constructor = {
1717
payload?: constructorPayload,
1818
}
1919

20+
type rec typeInSignature = {
21+
path: string,
22+
genericTypeParameters: array<typeInSignature>,
23+
}
24+
25+
type signatureDetails = {
26+
parameters: array<typeInSignature>,
27+
returnType: typeInSignature,
28+
}
29+
2030
@tag("kind")
2131
type detail =
2232
| @as("record") Record({items: array<field>})
2333
| @as("variant") Variant({items: array<constructor>})
34+
| @as("alias") Signature({details: signatureDetails})
2435

2536
type source = {
2637
filepath: string,
@@ -38,6 +49,8 @@ type rec item =
3849
name: string,
3950
deprecated?: string,
4051
source: source,
52+
/** Additional documentation of signature, if available. */
53+
detail?: detail,
4154
})
4255
| @as("type")
4356
Type({
@@ -89,4 +102,4 @@ type doc = {
89102
/**
90103
`decodeFromJson(json)` parse JSON generated from `restool doc` command
91104
*/
92-
external decodeFromJson: Js.Json.t => doc = "%identity"
105+
external decodeFromJson: JSON.t => doc = "%identity"

runtime/RescriptTools_Docgen.resi

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,22 @@ type constructor = {
1616
deprecated?: string,
1717
payload?: constructorPayload,
1818
}
19+
20+
type rec typeInSignature = {
21+
path: string,
22+
genericTypeParameters: array<typeInSignature>,
23+
}
24+
25+
type signatureDetails = {
26+
parameters: array<typeInSignature>,
27+
returnType: typeInSignature,
28+
}
29+
1930
@tag("kind")
2031
type detail =
2132
| @as("record") Record({items: array<field>})
2233
| @as("variant") Variant({items: array<constructor>})
34+
| @as("signature") Signature({details: signatureDetails})
2335

2436
type source = {
2537
filepath: string,
@@ -37,6 +49,8 @@ type rec item =
3749
name: string,
3850
deprecated?: string,
3951
source: source,
52+
/** Additional documentation of signature, if available. */
53+
detail?: detail,
4054
})
4155
| @as("type")
4256
Type({
@@ -85,4 +99,4 @@ type doc = {
8599
items: array<item>,
86100
}
87101

88-
let decodeFromJson: Js.Json.t => doc
102+
let decodeFromJson: JSON.t => doc

tests/tools_tests/package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tools_tests/src/expected/DocExtraction2.res.json

+24
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@
3030
"filepath": "src/DocExtraction2.resi",
3131
"line": 7,
3232
"col": 1
33+
},
34+
"detail":
35+
{
36+
"kind": "signature",
37+
"details": {
38+
"parameters": [{
39+
"path": "unit"
40+
}],
41+
"returnType": {
42+
"path": "t"
43+
}
44+
}
3345
}
3446
},
3547
{
@@ -65,6 +77,18 @@
6577
"filepath": "src/DocExtraction2.resi",
6678
"line": 15,
6779
"col": 3
80+
},
81+
"detail":
82+
{
83+
"kind": "signature",
84+
"details": {
85+
"parameters": [{
86+
"path": "unit"
87+
}],
88+
"returnType": {
89+
"path": "t"
90+
}
91+
}
6892
}
6993
}]
7094
}]

tests/tools_tests/src/expected/DocExtraction2.resi.json

+24
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@
3030
"filepath": "src/DocExtraction2.resi",
3131
"line": 7,
3232
"col": 1
33+
},
34+
"detail":
35+
{
36+
"kind": "signature",
37+
"details": {
38+
"parameters": [{
39+
"path": "unit"
40+
}],
41+
"returnType": {
42+
"path": "t"
43+
}
44+
}
3345
}
3446
},
3547
{
@@ -65,6 +77,18 @@
6577
"filepath": "src/DocExtraction2.resi",
6678
"line": 15,
6779
"col": 3
80+
},
81+
"detail":
82+
{
83+
"kind": "signature",
84+
"details": {
85+
"parameters": [{
86+
"path": "unit"
87+
}],
88+
"returnType": {
89+
"path": "t"
90+
}
91+
}
6892
}
6993
}]
7094
}]

tests/tools_tests/src/expected/DocExtractionRes.res.json

+108
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545
"filepath": "src/DocExtractionRes.res",
4646
"line": 17,
4747
"col": 5
48+
},
49+
"detail":
50+
{
51+
"kind": "signature",
52+
"details": {
53+
"parameters": [{
54+
"path": "string"
55+
}],
56+
"returnType": {
57+
"path": "t"
58+
}
59+
}
4860
}
4961
},
5062
{
@@ -57,6 +69,18 @@
5769
"filepath": "src/DocExtractionRes.res",
5870
"line": 23,
5971
"col": 5
72+
},
73+
"detail":
74+
{
75+
"kind": "signature",
76+
"details": {
77+
"parameters": [{
78+
"path": "t"
79+
}],
80+
"returnType": {
81+
"path": "t"
82+
}
83+
}
6084
}
6185
},
6286
{
@@ -69,6 +93,15 @@
6993
"filepath": "src/DocExtractionRes.res",
7094
"line": 26,
7195
"col": 5
96+
},
97+
"detail":
98+
{
99+
"kind": "signature",
100+
"details": {
101+
"returnType": {
102+
"path": "int"
103+
}
104+
}
72105
}
73106
},
74107
{
@@ -184,6 +217,18 @@
184217
"filepath": "src/DocExtractionRes.res",
185218
"line": 49,
186219
"col": 7
220+
},
221+
"detail":
222+
{
223+
"kind": "signature",
224+
"details": {
225+
"parameters": [{
226+
"path": "SomeInnerModule.status"
227+
}],
228+
"returnType": {
229+
"path": "bool"
230+
}
231+
}
187232
}
188233
},
189234
{
@@ -268,6 +313,18 @@
268313
"filepath": "src/DocExtractionRes.res",
269314
"line": 71,
270315
"col": 3
316+
},
317+
"detail":
318+
{
319+
"kind": "signature",
320+
"details": {
321+
"parameters": [{
322+
"path": "unit"
323+
}],
324+
"returnType": {
325+
"path": "t"
326+
}
327+
}
271328
}
272329
}]
273330
},
@@ -304,6 +361,18 @@
304361
"filepath": "src/DocExtractionRes.res",
305362
"line": 109,
306363
"col": 3
364+
},
365+
"detail":
366+
{
367+
"kind": "signature",
368+
"details": {
369+
"parameters": [{
370+
"path": "t"
371+
}],
372+
"returnType": {
373+
"path": "t"
374+
}
375+
}
307376
}
308377
}]
309378
},
@@ -341,6 +410,18 @@
341410
"filepath": "src/DocExtractionRes.res",
342411
"line": 128,
343412
"col": 7
413+
},
414+
"detail":
415+
{
416+
"kind": "signature",
417+
"details": {
418+
"parameters": [{
419+
"path": "int"
420+
}],
421+
"returnType": {
422+
"path": "int"
423+
}
424+
}
344425
}
345426
}]
346427
},
@@ -365,6 +446,15 @@
365446
"filepath": "src/DocExtractionRes.res",
366447
"line": 132,
367448
"col": 3
449+
},
450+
"detail":
451+
{
452+
"kind": "signature",
453+
"details": {
454+
"returnType": {
455+
"path": "int"
456+
}
457+
}
368458
}
369459
}]
370460
},
@@ -390,6 +480,15 @@
390480
"filepath": "src/DocExtractionRes.res",
391481
"line": 136,
392482
"col": 7
483+
},
484+
"detail":
485+
{
486+
"kind": "signature",
487+
"details": {
488+
"returnType": {
489+
"path": "int"
490+
}
491+
}
393492
}
394493
}]
395494
},
@@ -426,6 +525,15 @@
426525
"filepath": "src/DocExtractionRes.res",
427526
"line": 141,
428527
"col": 9
528+
},
529+
"detail":
530+
{
531+
"kind": "signature",
532+
"details": {
533+
"returnType": {
534+
"path": "int"
535+
}
536+
}
429537
}
430538
}]
431539
}]

tests/tools_tests/src/expected/ModC.res.json

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
"filepath": "src/ModC.resi",
3030
"line": 5,
3131
"col": 3
32+
},
33+
"detail":
34+
{
35+
"kind": "signature",
36+
"details": {
37+
"returnType": {
38+
"path": "string"
39+
}
40+
}
3241
}
3342
}]
3443
}]

tests/tools_tests/src/expected/ModC.resi.json

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
"filepath": "src/ModC.resi",
3030
"line": 5,
3131
"col": 3
32+
},
33+
"detail":
34+
{
35+
"kind": "signature",
36+
"details": {
37+
"returnType": {
38+
"path": "string"
39+
}
40+
}
3241
}
3342
}]
3443
}]

tools/bin/main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Usage: rescript-tools [command]
1414

1515
Commands:
1616

17-
doc Generate documentation
17+
doc <file> Generate documentation
1818
reanalyze Reanalyze
1919
-v, --version Print version
2020
-h, --help Print help|}

0 commit comments

Comments
 (0)