1
- type linkableType = {
2
- name : string ;
3
- modulePath : string list ;
4
- path : Path .t ;
5
- env : SharedTypes.QueryEnv .t ;
6
- loc : Location .t ;
7
- }
8
-
9
- type fieldDoc = {
10
- fieldName : string ;
11
- docstrings : string list ;
12
- signature : string ;
13
- linkables : linkableType list ;
14
- }
1
+ type fieldDoc = {fieldName : string ; docstrings : string list ; signature : string }
15
2
16
3
type constructorDoc = {
17
4
constructorName : string ;
18
5
docstrings : string list ;
19
6
signature : string ;
20
- linkables : linkableType list ;
21
7
}
22
8
23
9
type docItemDetail =
@@ -29,8 +15,6 @@ type docItem =
29
15
docstring : string list ;
30
16
signature : string ;
31
17
name : string ;
32
- linkables : linkableType list ;
33
- (* * Relevant types to link to, found in relation to this value. *)
34
18
}
35
19
| Type of {
36
20
id : string ;
@@ -39,8 +23,6 @@ type docItem =
39
23
name : string ;
40
24
detail : docItemDetail option ;
41
25
(* * Additional documentation for constructors and record fields, if available. *)
42
- linkables : linkableType list ;
43
- (* * Relevant types to link to, found in relation to this type. *)
44
26
}
45
27
| Module of docsForModule
46
28
and docsForModule = {
@@ -59,100 +41,13 @@ let formatCode content =
59
41
signature
60
42
|> String. trim
61
43
62
- module Linkables = struct
63
- (* TODO: Extend this by going into function arguments, tuples etc... *)
64
- let labelDeclarationsTypes lds =
65
- lds |> List. map (fun (ld : Types.label_declaration ) -> ld.ld_type)
66
-
67
- let rec linkablesFromDecl (decl : Types.type_declaration ) ~env ~full =
68
- match decl.type_kind with
69
- | Type_record (lds , _ ) -> (env, lds |> labelDeclarationsTypes)
70
- | Type_variant cds ->
71
- ( env,
72
- cds
73
- |> List. map (fun (cd : Types.constructor_declaration ) ->
74
- let fromArgs =
75
- match cd.cd_args with
76
- | Cstr_tuple ts -> ts
77
- | Cstr_record lds -> lds |> labelDeclarationsTypes
78
- in
79
- match cd.cd_res with
80
- | None -> fromArgs
81
- | Some t -> t :: fromArgs)
82
- |> List. flatten )
83
- | _ -> (
84
- match decl.type_manifest with
85
- | None -> (env, [] )
86
- | Some typ -> linkablesFromTyp typ ~env ~full )
87
-
88
- and linkablesFromTyp ~env ~(full : SharedTypes.full ) typ =
89
- match typ |> Shared. digConstructor with
90
- | Some path -> (
91
- match References. digConstructor ~env ~package: full.package path with
92
- | None -> (env, [typ])
93
- | Some (env1 , {item = {decl} } ) ->
94
- let env, types = linkablesFromDecl decl ~env: env1 ~full in
95
- (env, typ :: types))
96
- | None -> (env, [typ])
97
-
98
- type linkableSource =
99
- | Typ of SharedTypes.Type .t
100
- | TypeExpr of Types .type_expr
101
-
102
- let findLinkables ~env ~(full : SharedTypes.full ) (typ : linkableSource ) =
103
- (* Expand definitions of types mentioned in typ.
104
- If typ itself is a record or variant, search its body *)
105
- let envToSearch, typesToSearch =
106
- match typ with
107
- | Typ t -> linkablesFromDecl ~env t.decl ~full
108
- | TypeExpr t -> linkablesFromTyp t ~env ~full
109
- in
110
- let fromConstructorPath ~env path =
111
- match References. digConstructor ~env ~package: full.package path with
112
- | None -> None
113
- | Some (env , {name = {txt} ; extentLoc; modulePath} ) ->
114
- if Utils. isUncurriedInternal path then None
115
- else
116
- Some
117
- {
118
- name = txt;
119
- env;
120
- loc = extentLoc;
121
- modulePath = SharedTypes.ModulePath. toPath modulePath txt;
122
- path;
123
- }
124
- in
125
- let constructors = Shared. findTypeConstructors typesToSearch in
126
- constructors |> List. filter_map (fromConstructorPath ~env: envToSearch)
127
- end
128
-
129
44
let stringifyDocstrings docstrings =
130
45
let open Protocol in
131
46
docstrings
132
47
|> List. map (fun docstring -> docstring |> String. trim |> wrapInQuotes)
133
48
|> array
134
49
135
- let stringifyLinkables ?(indentation = 0 )
136
- ~(originalEnv : SharedTypes.QueryEnv.t ) (linkables : linkableType list ) =
137
- let open Protocol in
138
- linkables
139
- |> List. map (fun l ->
140
- let isExternal = originalEnv.file.uri <> l.env.file.uri in
141
- let linkId = l.env.file.moduleName :: l.modulePath in
142
- stringifyObject ~indentation: (indentation + 1 )
143
- [
144
- ( " linkId" ,
145
- Some (linkId |> SharedTypes. ident |> Json. escape |> wrapInQuotes)
146
- );
147
- ( " name" ,
148
- Some
149
- (l.path |> SharedTypes. pathIdentToString |> Json. escape
150
- |> wrapInQuotes) );
151
- (" external" , Some (Printf. sprintf " %b" isExternal));
152
- ])
153
- |> array
154
-
155
- let stringifyDetail ?(indentation = 0 ) ~originalEnv (detail : docItemDetail ) =
50
+ let stringifyDetail ?(indentation = 0 ) (detail : docItemDetail ) =
156
51
let open Protocol in
157
52
match detail with
158
53
| Record {fieldDocs} ->
@@ -169,10 +64,6 @@ let stringifyDetail ?(indentation = 0) ~originalEnv (detail : docItemDetail) =
169
64
( " docstrings" ,
170
65
Some (stringifyDocstrings fieldDoc.docstrings) );
171
66
(" signature" , Some (wrapInQuotes fieldDoc.signature));
172
- ( " linkables" ,
173
- Some
174
- (stringifyLinkables ~indentation: (indentation + 1 )
175
- ~original Env fieldDoc.linkables) );
176
67
])
177
68
|> array ) );
178
69
]
@@ -193,18 +84,14 @@ let stringifyDetail ?(indentation = 0) ~originalEnv (detail : docItemDetail) =
193
84
Some (stringifyDocstrings constructorDoc.docstrings) );
194
85
( " signature" ,
195
86
Some (wrapInQuotes constructorDoc.signature) );
196
- ( " linkables" ,
197
- Some
198
- (stringifyLinkables ~indentation: (indentation + 1 )
199
- ~original Env constructorDoc.linkables) );
200
87
])
201
88
|> array ) );
202
89
]
203
90
204
91
let rec stringifyDocItem ?(indentation = 0 ) ~originalEnv (item : docItem ) =
205
92
let open Protocol in
206
93
match item with
207
- | Value {id; docstring; signature; name; linkables } ->
94
+ | Value {id; docstring; signature; name} ->
208
95
stringifyObject ~start OnNewline:true ~indentation
209
96
[
210
97
(" id" , Some (wrapInQuotes id));
@@ -213,30 +100,20 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
213
100
( " signature" ,
214
101
Some (signature |> String. trim |> Json. escape |> wrapInQuotes) );
215
102
(" docstrings" , Some (stringifyDocstrings docstring));
216
- ( " linkables" ,
217
- Some
218
- (stringifyLinkables ~original Env ~indentation: (indentation + 1 )
219
- linkables) );
220
103
]
221
- | Type {id; docstring; signature; name; detail; linkables } ->
104
+ | Type {id; docstring; signature; name; detail} ->
222
105
stringifyObject ~start OnNewline:true ~indentation
223
106
[
224
107
(" id" , Some (wrapInQuotes id));
225
108
(" kind" , Some (wrapInQuotes " type" ));
226
109
(" name" , Some (name |> Json. escape |> wrapInQuotes));
227
110
(" signature" , Some (signature |> Json. escape |> wrapInQuotes));
228
111
(" docstrings" , Some (stringifyDocstrings docstring));
229
- ( " linkables" ,
230
- Some
231
- (stringifyLinkables ~original Env ~indentation: (indentation + 1 )
232
- linkables) );
233
112
( " detail" ,
234
113
match detail with
235
114
| None -> None
236
115
| Some detail ->
237
- Some
238
- (stringifyDetail ~original Env ~indentation: (indentation + 1 )
239
- detail) );
116
+ Some (stringifyDetail ~indentation: (indentation + 1 ) detail) );
240
117
]
241
118
| Module m ->
242
119
stringifyObject ~start OnNewline:true ~indentation
@@ -277,8 +154,6 @@ let typeDetail typ ~env ~full =
277
154
fieldName = field.fname.txt;
278
155
docstrings = field.docstring;
279
156
signature = Shared. typeToString field.typ;
280
- linkables =
281
- TypeExpr field.typ |> Linkables. findLinkables ~env ~full ;
282
157
});
283
158
})
284
159
| Some (Tvariant {constructors} ) ->
@@ -288,20 +163,10 @@ let typeDetail typ ~env ~full =
288
163
constructorDocs =
289
164
constructors
290
165
|> List. map (fun (c : Constructor.t ) ->
291
- let linkables =
292
- (match c.args with
293
- | Args args -> args |> List. map (fun (t , _ ) -> t)
294
- | InlineRecord fields ->
295
- fields |> List. map (fun f -> f.typ))
296
- |> List. map (fun t ->
297
- TypeExpr t |> Linkables. findLinkables ~env ~full )
298
- |> List. flatten
299
- in
300
166
{
301
167
constructorName = c.cname.txt;
302
168
docstrings = c.docstring;
303
169
signature = CompletionBackEnd. showConstructor c;
304
- linkables;
305
170
});
306
171
})
307
172
| _ -> None
@@ -358,16 +223,12 @@ let extractDocs ~path ~debug =
358
223
" let " ^ item.name ^ " : " ^ Shared. typeToString typ
359
224
|> formatCode;
360
225
name = item.name;
361
- linkables =
362
- TypeExpr typ |> Linkables. findLinkables ~env ~full ;
363
226
})
364
227
| Type (typ , _ ) ->
365
228
Some
366
229
(Type
367
230
{
368
231
id = modulePath |> makeId ~identifier: item.name;
369
- linkables =
370
- Typ typ |> Linkables. findLinkables ~env ~full ;
371
232
docstring = item.docstring |> List. map String. trim;
372
233
signature =
373
234
typ.decl
0 commit comments