Skip to content

Commit 786380f

Browse files
committed
rename constructor payload field and prepare for potentially adding more detail for other constructor payload types as well
1 parent e16a60d commit 786380f

File tree

4 files changed

+54
-25
lines changed

4 files changed

+54
-25
lines changed

analysis/src/DocExtraction.ml

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ type fieldDoc = {
66
deprecated: string option;
77
}
88

9+
type constructorPayload = InlineRecord of {fieldDocs: fieldDoc list}
10+
911
type constructorDoc = {
1012
constructorName: string;
1113
docstrings: string list;
1214
signature: string;
1315
deprecated: string option;
14-
inlineRecordFields: fieldDoc list option;
16+
items: constructorPayload option;
1517
}
1618

1719
type docItemDetail =
@@ -69,6 +71,21 @@ let stringifyFieldDoc ~indentation (fieldDoc : fieldDoc) =
6971
("signature", Some (wrapInQuotes fieldDoc.signature));
7072
]
7173

74+
let stringifyConstructorPayload ~indentation
75+
(constructorPayload : constructorPayload) =
76+
let open Protocol in
77+
match constructorPayload with
78+
| InlineRecord {fieldDocs} ->
79+
stringifyObject ~indentation:(indentation + 1)
80+
[
81+
("kind", Some (wrapInQuotes "inlineRecord"));
82+
( "fields",
83+
Some
84+
(fieldDocs
85+
|> List.map (stringifyFieldDoc ~indentation:(indentation + 1))
86+
|> array) );
87+
]
88+
7289
let stringifyDetail ?(indentation = 0) (detail : docItemDetail) =
7390
let open Protocol in
7491
match detail with
@@ -101,16 +118,14 @@ let stringifyDetail ?(indentation = 0) (detail : docItemDetail) =
101118
Some (stringifyDocstrings constructorDoc.docstrings) );
102119
( "signature",
103120
Some (wrapInQuotes constructorDoc.signature) );
104-
( "inlineRecordFields",
105-
match constructorDoc.inlineRecordFields with
121+
( "items",
122+
match constructorDoc.items with
106123
| None -> None
107-
| Some fieldDocs ->
124+
| Some constructorPayload ->
108125
Some
109-
(fieldDocs
110-
|> List.map
111-
(stringifyFieldDoc
112-
~indentation:(indentation + 1))
113-
|> array) );
126+
(stringifyConstructorPayload
127+
~indentation:(indentation + 1)
128+
constructorPayload) );
114129
])
115130
|> array) );
116131
]
@@ -223,10 +238,12 @@ let typeDetail typ ~env ~full =
223238
docstrings = c.docstring;
224239
signature = CompletionBackEnd.showConstructor c;
225240
deprecated = c.deprecated;
226-
inlineRecordFields =
241+
items =
227242
(match c.args with
228243
| InlineRecord fields ->
229-
Some (fields |> List.map fieldToFieldDoc)
244+
Some
245+
(InlineRecord
246+
{fieldDocs = fields |> List.map fieldToFieldDoc})
230247
| _ -> None);
231248
});
232249
})
@@ -325,7 +342,9 @@ let extractDocs ~path ~debug =
325342
id;
326343
name = item.name;
327344
items;
328-
docstring = item.docstring @ internalDocstrings |> List.map String.trim;
345+
docstring =
346+
item.docstring @ internalDocstrings
347+
|> List.map String.trim;
329348
})
330349
| Module (Structure m) ->
331350
(* module Whatever = {} in res or module Whatever: {} in resi. *)

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,20 @@ extracting docs for src/DocExtractionRes.res
137137
"name": "SomeStuff",
138138
"docstrings": ["This has inline records..."],
139139
"signature": "SomeStuff({offline: bool, online?: bool})",
140-
"inlineRecordFields": [{
141-
"name": "offline",
142-
"optional": false,
143-
"docstrings": [],
144-
"signature": "bool"
145-
}, {
146-
"name": "online",
147-
"optional": true,
148-
"docstrings": ["Is the user online?"],
149-
"signature": "option<bool>"
150-
}]
140+
"items": {
141+
"kind": "inlineRecord",
142+
"fields": [{
143+
"name": "offline",
144+
"optional": false,
145+
"docstrings": [],
146+
"signature": "bool"
147+
}, {
148+
"name": "online",
149+
"optional": true,
150+
"docstrings": ["Is the user online?"],
151+
"signature": "option<bool>"
152+
}]
153+
}
151154
}]
152155
}
153156
},

tools/src/Tools_Docgen.res

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ type field = {
66
deprecated?: string,
77
}
88

9+
@tag("kind")
10+
type constructorPayload = | @as("inlineRecord") InlineRecord({fields: array<field>})
11+
912
type constructor = {
1013
name: string,
1114
docstrings: array<string>,
1215
signature: string,
1316
deprecated?: string,
14-
inlineRecordFields?: array<field>,
17+
constructorPayload?: constructorPayload,
1518
}
1619

1720
@tag("kind")

tools/src/Tools_Docgen.resi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ type field = {
55
optional: bool,
66
deprecated?: string,
77
}
8+
9+
@tag("kind")
10+
type constructorPayload = | @as("inlineRecord") InlineRecord({fields: array<field>})
11+
812
type constructor = {
913
name: string,
1014
docstrings: array<string>,
1115
signature: string,
1216
deprecated?: string,
13-
inlineRecordFields?: array<field>,
17+
constructorPayload?: constructorPayload,
1418
}
1519
@tag("kind")
1620
type detail =

0 commit comments

Comments
 (0)