@@ -6,11 +6,14 @@ type fieldDoc = {
6
6
deprecated : string option ;
7
7
}
8
8
9
+ type constructorPayload = InlineRecord of {fieldDocs : fieldDoc list }
10
+
9
11
type constructorDoc = {
10
12
constructorName : string ;
11
13
docstrings : string list ;
12
14
signature : string ;
13
15
deprecated : string option ;
16
+ items : constructorPayload option ;
14
17
}
15
18
16
19
type docItemDetail =
@@ -54,6 +57,35 @@ let stringifyDocstrings docstrings =
54
57
|> List. map (fun docstring -> docstring |> String. trim |> wrapInQuotes)
55
58
|> array
56
59
60
+ let stringifyFieldDoc ~indentation (fieldDoc : fieldDoc ) =
61
+ let open Protocol in
62
+ stringifyObject ~indentation: (indentation + 1 )
63
+ [
64
+ (" name" , Some (wrapInQuotes fieldDoc.fieldName));
65
+ ( " deprecated" ,
66
+ match fieldDoc.deprecated with
67
+ | Some d -> Some (wrapInQuotes d)
68
+ | None -> None );
69
+ (" optional" , Some (string_of_bool fieldDoc.optional));
70
+ (" docstrings" , Some (stringifyDocstrings fieldDoc.docstrings));
71
+ (" signature" , Some (wrapInQuotes fieldDoc.signature));
72
+ ]
73
+
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
+
57
89
let stringifyDetail ?(indentation = 0 ) (detail : docItemDetail ) =
58
90
let open Protocol in
59
91
match detail with
@@ -62,22 +94,8 @@ let stringifyDetail ?(indentation = 0) (detail : docItemDetail) =
62
94
[
63
95
(" kind" , Some (wrapInQuotes " record" ));
64
96
( " items" ,
65
- Some
66
- (fieldDocs
67
- |> List. map (fun fieldDoc ->
68
- stringifyObject ~indentation: (indentation + 1 )
69
- [
70
- (" name" , Some (wrapInQuotes fieldDoc.fieldName));
71
- ( " deprecated" ,
72
- match fieldDoc.deprecated with
73
- | Some d -> Some (wrapInQuotes d)
74
- | None -> None );
75
- (" optional" , Some (string_of_bool fieldDoc.optional));
76
- ( " docstrings" ,
77
- Some (stringifyDocstrings fieldDoc.docstrings) );
78
- (" signature" , Some (wrapInQuotes fieldDoc.signature));
79
- ])
80
- |> array ) );
97
+ Some (fieldDocs |> List. map (stringifyFieldDoc ~indentation ) |> array )
98
+ );
81
99
]
82
100
| Variant {constructorDocs} ->
83
101
stringifyObject ~start OnNewline:true ~indentation
@@ -100,6 +118,14 @@ let stringifyDetail ?(indentation = 0) (detail : docItemDetail) =
100
118
Some (stringifyDocstrings constructorDoc.docstrings) );
101
119
( " signature" ,
102
120
Some (wrapInQuotes constructorDoc.signature) );
121
+ ( " payload" ,
122
+ match constructorDoc.items with
123
+ | None -> None
124
+ | Some constructorPayload ->
125
+ Some
126
+ (stringifyConstructorPayload
127
+ ~indentation: (indentation + 1 )
128
+ constructorPayload) );
103
129
])
104
130
|> array ) );
105
131
]
@@ -145,6 +171,7 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
145
171
(" id" , Some (wrapInQuotes m.id));
146
172
(" name" , Some (wrapInQuotes m.name));
147
173
(" kind" , Some (wrapInQuotes " module" ));
174
+ (" docstrings" , Some (stringifyDocstrings m.docstring));
148
175
( " items" ,
149
176
Some
150
177
(m.items
@@ -185,24 +212,20 @@ and stringifyDocsForModule ?(indentation = 0) ~originalEnv (d : docsForModule) =
185
212
|> array ) );
186
213
]
187
214
215
+ let fieldToFieldDoc (field : SharedTypes.field ) : fieldDoc =
216
+ {
217
+ fieldName = field.fname.txt;
218
+ docstrings = field.docstring;
219
+ optional = field.optional;
220
+ signature = Shared. typeToString field.typ;
221
+ deprecated = field.deprecated;
222
+ }
223
+
188
224
let typeDetail typ ~env ~full =
189
225
let open SharedTypes in
190
226
match TypeUtils. extractTypeFromResolvedType ~env ~full typ with
191
227
| Some (Trecord {fields} ) ->
192
- Some
193
- (Record
194
- {
195
- fieldDocs =
196
- fields
197
- |> List. map (fun (field : field ) ->
198
- {
199
- fieldName = field.fname.txt;
200
- docstrings = field.docstring;
201
- optional = field.optional;
202
- signature = Shared. typeToString field.typ;
203
- deprecated = field.deprecated;
204
- });
205
- })
228
+ Some (Record {fieldDocs = fields |> List. map fieldToFieldDoc})
206
229
| Some (Tvariant {constructors} ) ->
207
230
Some
208
231
(Variant
@@ -215,6 +238,13 @@ let typeDetail typ ~env ~full =
215
238
docstrings = c.docstring;
216
239
signature = CompletionBackEnd. showConstructor c;
217
240
deprecated = c.deprecated;
241
+ items =
242
+ (match c.args with
243
+ | InlineRecord fields ->
244
+ Some
245
+ (InlineRecord
246
+ {fieldDocs = fields |> List. map fieldToFieldDoc})
247
+ | _ -> None );
218
248
});
219
249
})
220
250
| _ -> None
@@ -312,7 +342,9 @@ let extractDocs ~path ~debug =
312
342
id;
313
343
name = item.name;
314
344
items;
315
- docstring = item.docstring @ internalDocstrings |> List. map String. trim;
345
+ docstring =
346
+ item.docstring @ internalDocstrings
347
+ |> List. map String. trim;
316
348
})
317
349
| Module (Structure m ) ->
318
350
(* module Whatever = {} in res or module Whatever: {} in resi. *)
0 commit comments