@@ -5,12 +5,18 @@ type linkableType = {
5
5
loc : Location .t ;
6
6
}
7
7
8
- type fieldDoc = {fieldName : string ; docstrings : string list ; signature : string }
8
+ type fieldDoc = {
9
+ fieldName : string ;
10
+ docstrings : string list ;
11
+ signature : string ;
12
+ linkables : linkableType list ;
13
+ }
9
14
10
15
type constructorDoc = {
11
16
constructorName : string ;
12
17
docstrings : string list ;
13
18
signature : string ;
19
+ linkables : linkableType list ;
14
20
}
15
21
16
22
type docItemDetail =
@@ -83,7 +89,9 @@ module Linkables = struct
83
89
| Some path -> (
84
90
match References. digConstructor ~env ~package: full.package path with
85
91
| None -> (env, [typ])
86
- | Some (env1 , {item = {decl} } ) -> linkablesFromDecl decl ~env: env1 ~full )
92
+ | Some (env1 , {item = {decl} } ) ->
93
+ let env, types = linkablesFromDecl decl ~env: env1 ~full in
94
+ (env, typ :: types))
87
95
| None -> (env, [typ])
88
96
89
97
type linkableSource =
@@ -138,7 +146,7 @@ let stringifyLinkables ?(indentation = 0)
138
146
])
139
147
|> array
140
148
141
- let stringifyDetail ?(indentation = 0 ) (detail : docItemDetail ) =
149
+ let stringifyDetail ?(indentation = 0 ) ~ originalEnv (detail : docItemDetail ) =
142
150
let open Protocol in
143
151
match detail with
144
152
| Record {fieldDocs} ->
@@ -155,6 +163,10 @@ let stringifyDetail ?(indentation = 0) (detail : docItemDetail) =
155
163
( " docstrings" ,
156
164
Some (stringifyDocstrings fieldDoc.docstrings) );
157
165
(" signature" , Some (wrapInQuotes fieldDoc.signature));
166
+ ( " linkables" ,
167
+ Some
168
+ (stringifyLinkables ~indentation: (indentation + 1 )
169
+ ~original Env fieldDoc.linkables) );
158
170
])
159
171
|> array ) );
160
172
]
@@ -175,6 +187,10 @@ let stringifyDetail ?(indentation = 0) (detail : docItemDetail) =
175
187
Some (stringifyDocstrings constructorDoc.docstrings) );
176
188
( " signature" ,
177
189
Some (wrapInQuotes constructorDoc.signature) );
190
+ ( " linkables" ,
191
+ Some
192
+ (stringifyLinkables ~indentation: (indentation + 1 )
193
+ ~original Env constructorDoc.linkables) );
178
194
])
179
195
|> array ) );
180
196
]
@@ -212,7 +228,9 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
212
228
match detail with
213
229
| None -> None
214
230
| Some detail ->
215
- Some (stringifyDetail ~indentation: (indentation + 1 ) detail) );
231
+ Some
232
+ (stringifyDetail ~original Env ~indentation: (indentation + 1 )
233
+ detail) );
216
234
]
217
235
| Module m ->
218
236
stringifyObject ~start OnNewline:true ~indentation
@@ -239,6 +257,49 @@ and stringifyDocsForModule ?(indentation = 0) ~originalEnv (d : docsForModule) =
239
257
|> array ) );
240
258
]
241
259
260
+ let typeDetail typ ~env ~full =
261
+ let open SharedTypes in
262
+ match TypeUtils. extractTypeFromResolvedType ~env ~full typ with
263
+ | Some (Trecord {fields} ) ->
264
+ Some
265
+ (Record
266
+ {
267
+ fieldDocs =
268
+ fields
269
+ |> List. map (fun (field : field ) ->
270
+ {
271
+ fieldName = field.fname.txt;
272
+ docstrings = field.docstring;
273
+ signature = Shared. typeToString field.typ;
274
+ linkables =
275
+ TypeExpr field.typ |> Linkables. findLinkables ~env ~full ;
276
+ });
277
+ })
278
+ | Some (Tvariant {constructors} ) ->
279
+ Some
280
+ (Variant
281
+ {
282
+ constructorDocs =
283
+ constructors
284
+ |> List. map (fun (c : Constructor.t ) ->
285
+ let linkables =
286
+ (match c.args with
287
+ | Args args -> args |> List. map (fun (t , _ ) -> t)
288
+ | InlineRecord fields ->
289
+ fields |> List. map (fun f -> f.typ))
290
+ |> List. map (fun t ->
291
+ TypeExpr t |> Linkables. findLinkables ~env ~full )
292
+ |> List. flatten
293
+ in
294
+ {
295
+ constructorName = c.cname.txt;
296
+ docstrings = c.docstring;
297
+ signature = CompletionBackEnd. showConstructor c;
298
+ linkables;
299
+ });
300
+ })
301
+ | _ -> None
302
+
242
303
exception Invalid_file_type
243
304
244
305
let makeId modulePath ~identifier =
@@ -307,41 +368,7 @@ let extractDocs ~path ~debug =
307
368
|> Shared. declToString item.name
308
369
|> formatCode;
309
370
name = item.name;
310
- detail =
311
- (match
312
- TypeUtils. extractTypeFromResolvedType ~env ~full
313
- typ
314
- with
315
- | Some (Trecord {fields} ) ->
316
- Some
317
- (Record
318
- {
319
- fieldDocs =
320
- fields
321
- |> List. map (fun (field : field ) ->
322
- {
323
- fieldName = field.fname.txt;
324
- docstrings = field.docstring;
325
- signature =
326
- Shared. typeToString field.typ;
327
- });
328
- })
329
- | Some (Tvariant {constructors} ) ->
330
- Some
331
- (Variant
332
- {
333
- constructorDocs =
334
- constructors
335
- |> List. map (fun (c : Constructor.t ) ->
336
- {
337
- constructorName = c.cname.txt;
338
- docstrings = c.docstring;
339
- signature =
340
- CompletionBackEnd
341
- .showConstructor c;
342
- });
343
- })
344
- | _ -> None );
371
+ detail = typeDetail typ ~full ~env ;
345
372
})
346
373
| Module (Structure m ) ->
347
374
(* module Whatever = {} in res or module Whatever: {} in resi. *)
0 commit comments