@@ -6,11 +6,14 @@ type fieldDoc = {
66 deprecated : string option ;
77}
88
9+ type constructorPayload = InlineRecord of {fieldDocs : fieldDoc list }
10+
911type constructorDoc = {
1012 constructorName : string ;
1113 docstrings : string list ;
1214 signature : string ;
1315 deprecated : string option ;
16+ items : constructorPayload option ;
1417}
1518
1619type docItemDetail =
@@ -54,6 +57,35 @@ let stringifyDocstrings docstrings =
5457 |> List. map (fun docstring -> docstring |> String. trim |> wrapInQuotes)
5558 |> array
5659
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+
5789let stringifyDetail ?(indentation = 0 ) (detail : docItemDetail ) =
5890 let open Protocol in
5991 match detail with
@@ -62,22 +94,8 @@ let stringifyDetail ?(indentation = 0) (detail : docItemDetail) =
6294 [
6395 (" kind" , Some (wrapInQuotes " record" ));
6496 ( " 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+ );
8199 ]
82100 | Variant {constructorDocs} ->
83101 stringifyObject ~start OnNewline:true ~indentation
@@ -100,6 +118,14 @@ let stringifyDetail ?(indentation = 0) (detail : docItemDetail) =
100118 Some (stringifyDocstrings constructorDoc.docstrings) );
101119 ( " signature" ,
102120 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) );
103129 ])
104130 |> array ) );
105131 ]
@@ -145,6 +171,7 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
145171 (" id" , Some (wrapInQuotes m.id));
146172 (" name" , Some (wrapInQuotes m.name));
147173 (" kind" , Some (wrapInQuotes " module" ));
174+ (" docstrings" , Some (stringifyDocstrings m.docstring));
148175 ( " items" ,
149176 Some
150177 (m.items
@@ -185,24 +212,20 @@ and stringifyDocsForModule ?(indentation = 0) ~originalEnv (d : docsForModule) =
185212 |> array ) );
186213 ]
187214
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+
188224let typeDetail typ ~env ~full =
189225 let open SharedTypes in
190226 match TypeUtils. extractTypeFromResolvedType ~env ~full typ with
191227 | 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})
206229 | Some (Tvariant {constructors} ) ->
207230 Some
208231 (Variant
@@ -215,6 +238,13 @@ let typeDetail typ ~env ~full =
215238 docstrings = c.docstring;
216239 signature = CompletionBackEnd. showConstructor c;
217240 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 );
218248 });
219249 })
220250 | _ -> None
@@ -312,7 +342,9 @@ let extractDocs ~path ~debug =
312342 id;
313343 name = item.name;
314344 items;
315- docstring = item.docstring @ internalDocstrings |> List. map String. trim;
345+ docstring =
346+ item.docstring @ internalDocstrings
347+ |> List. map String. trim;
316348 })
317349 | Module (Structure m ) ->
318350 (* module Whatever = {} in res or module Whatever: {} in resi. *)
0 commit comments