Skip to content

Commit db1e2ef

Browse files
zthGabriel Nordeborn
authored and
Gabriel Nordeborn
committed
remove linkables concept
1 parent 87208ea commit db1e2ef

File tree

4 files changed

+28
-249
lines changed

4 files changed

+28
-249
lines changed

analysis/src/DocExtraction.ml

Lines changed: 5 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
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}
152

163
type constructorDoc = {
174
constructorName: string;
185
docstrings: string list;
196
signature: string;
20-
linkables: linkableType list;
217
}
228

239
type docItemDetail =
@@ -29,8 +15,6 @@ type docItem =
2915
docstring: string list;
3016
signature: string;
3117
name: string;
32-
linkables: linkableType list;
33-
(** Relevant types to link to, found in relation to this value. *)
3418
}
3519
| Type of {
3620
id: string;
@@ -39,8 +23,6 @@ type docItem =
3923
name: string;
4024
detail: docItemDetail option;
4125
(** 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. *)
4426
}
4527
| Module of docsForModule
4628
and docsForModule = {
@@ -59,100 +41,13 @@ let formatCode content =
5941
signature
6042
|> String.trim
6143

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-
12944
let stringifyDocstrings docstrings =
13045
let open Protocol in
13146
docstrings
13247
|> List.map (fun docstring -> docstring |> String.trim |> wrapInQuotes)
13348
|> array
13449

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) =
15651
let open Protocol in
15752
match detail with
15853
| Record {fieldDocs} ->
@@ -169,10 +64,6 @@ let stringifyDetail ?(indentation = 0) ~originalEnv (detail : docItemDetail) =
16964
( "docstrings",
17065
Some (stringifyDocstrings fieldDoc.docstrings) );
17166
("signature", Some (wrapInQuotes fieldDoc.signature));
172-
( "linkables",
173-
Some
174-
(stringifyLinkables ~indentation:(indentation + 1)
175-
~originalEnv fieldDoc.linkables) );
17667
])
17768
|> array) );
17869
]
@@ -193,18 +84,14 @@ let stringifyDetail ?(indentation = 0) ~originalEnv (detail : docItemDetail) =
19384
Some (stringifyDocstrings constructorDoc.docstrings) );
19485
( "signature",
19586
Some (wrapInQuotes constructorDoc.signature) );
196-
( "linkables",
197-
Some
198-
(stringifyLinkables ~indentation:(indentation + 1)
199-
~originalEnv constructorDoc.linkables) );
20087
])
20188
|> array) );
20289
]
20390

20491
let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
20592
let open Protocol in
20693
match item with
207-
| Value {id; docstring; signature; name; linkables} ->
94+
| Value {id; docstring; signature; name} ->
20895
stringifyObject ~startOnNewline:true ~indentation
20996
[
21097
("id", Some (wrapInQuotes id));
@@ -213,30 +100,20 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
213100
( "signature",
214101
Some (signature |> String.trim |> Json.escape |> wrapInQuotes) );
215102
("docstrings", Some (stringifyDocstrings docstring));
216-
( "linkables",
217-
Some
218-
(stringifyLinkables ~originalEnv ~indentation:(indentation + 1)
219-
linkables) );
220103
]
221-
| Type {id; docstring; signature; name; detail; linkables} ->
104+
| Type {id; docstring; signature; name; detail} ->
222105
stringifyObject ~startOnNewline:true ~indentation
223106
[
224107
("id", Some (wrapInQuotes id));
225108
("kind", Some (wrapInQuotes "type"));
226109
("name", Some (name |> Json.escape |> wrapInQuotes));
227110
("signature", Some (signature |> Json.escape |> wrapInQuotes));
228111
("docstrings", Some (stringifyDocstrings docstring));
229-
( "linkables",
230-
Some
231-
(stringifyLinkables ~originalEnv ~indentation:(indentation + 1)
232-
linkables) );
233112
( "detail",
234113
match detail with
235114
| None -> None
236115
| Some detail ->
237-
Some
238-
(stringifyDetail ~originalEnv ~indentation:(indentation + 1)
239-
detail) );
116+
Some (stringifyDetail ~indentation:(indentation + 1) detail) );
240117
]
241118
| Module m ->
242119
stringifyObject ~startOnNewline:true ~indentation
@@ -277,8 +154,6 @@ let typeDetail typ ~env ~full =
277154
fieldName = field.fname.txt;
278155
docstrings = field.docstring;
279156
signature = Shared.typeToString field.typ;
280-
linkables =
281-
TypeExpr field.typ |> Linkables.findLinkables ~env ~full;
282157
});
283158
})
284159
| Some (Tvariant {constructors}) ->
@@ -288,20 +163,10 @@ let typeDetail typ ~env ~full =
288163
constructorDocs =
289164
constructors
290165
|> 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
300166
{
301167
constructorName = c.cname.txt;
302168
docstrings = c.docstring;
303169
signature = CompletionBackEnd.showConstructor c;
304-
linkables;
305170
});
306171
})
307172
| _ -> None
@@ -358,16 +223,12 @@ let extractDocs ~path ~debug =
358223
"let " ^ item.name ^ ": " ^ Shared.typeToString typ
359224
|> formatCode;
360225
name = item.name;
361-
linkables =
362-
TypeExpr typ |> Linkables.findLinkables ~env ~full;
363226
})
364227
| Type (typ, _) ->
365228
Some
366229
(Type
367230
{
368231
id = modulePath |> makeId ~identifier:item.name;
369-
linkables =
370-
Typ typ |> Linkables.findLinkables ~env ~full;
371232
docstring = item.docstring |> List.map String.trim;
372233
signature =
373234
typ.decl

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,14 @@ preferring found resi file for impl: src/DocExtraction2.resi
1111
"kind": "type",
1212
"name": "t",
1313
"signature": "type t",
14-
"docstrings": ["Type t is pretty cool."],
15-
"linkables": []
14+
"docstrings": ["Type t is pretty cool."]
1615
},
1716
{
1817
"id": "DocExtraction2.make",
1918
"kind": "value",
2019
"name": "make",
2120
"signature": "let make: unit => t",
22-
"docstrings": ["Makerz of stuffz."],
23-
"linkables": [{
24-
"linkId": "DocExtraction2.t",
25-
"name": "t",
26-
"external": false
27-
}]
21+
"docstrings": ["Makerz of stuffz."]
2822
},
2923
{
3024
"id": "InnerModule.DocExtraction2",
@@ -39,20 +33,14 @@ preferring found resi file for impl: src/DocExtraction2.resi
3933
"kind": "type",
4034
"name": "t",
4135
"signature": "type t",
42-
"docstrings": ["This type is also t."],
43-
"linkables": []
36+
"docstrings": ["This type is also t."]
4437
},
4538
{
4639
"id": "DocExtraction2.InnerModule.make",
4740
"kind": "value",
4841
"name": "make",
4942
"signature": "let make: unit => t",
50-
"docstrings": ["Maker of tea."],
51-
"linkables": [{
52-
"linkId": "DocExtraction2.InnerModule.t",
53-
"name": "t",
54-
"external": false
55-
}]
43+
"docstrings": ["Maker of tea."]
5644
}]
5745
}
5846
}]

analysis/tests/src/expected/DocExtraction2.resi.txt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,14 @@ extracting docs for src/DocExtraction2.resi
1010
"kind": "type",
1111
"name": "t",
1212
"signature": "type t",
13-
"docstrings": ["Type t is pretty cool."],
14-
"linkables": []
13+
"docstrings": ["Type t is pretty cool."]
1514
},
1615
{
1716
"id": "DocExtraction2.make",
1817
"kind": "value",
1918
"name": "make",
2019
"signature": "let make: unit => t",
21-
"docstrings": ["Makerz of stuffz."],
22-
"linkables": [{
23-
"linkId": "DocExtraction2.t",
24-
"name": "t",
25-
"external": false
26-
}]
20+
"docstrings": ["Makerz of stuffz."]
2721
},
2822
{
2923
"id": "InnerModule.DocExtraction2",
@@ -38,20 +32,14 @@ extracting docs for src/DocExtraction2.resi
3832
"kind": "type",
3933
"name": "t",
4034
"signature": "type t",
41-
"docstrings": ["This type is also t."],
42-
"linkables": []
35+
"docstrings": ["This type is also t."]
4336
},
4437
{
4538
"id": "DocExtraction2.InnerModule.make",
4639
"kind": "value",
4740
"name": "make",
4841
"signature": "let make: unit => t",
49-
"docstrings": ["Maker of tea."],
50-
"linkables": [{
51-
"linkId": "DocExtraction2.InnerModule.t",
52-
"name": "t",
53-
"external": false
54-
}]
42+
"docstrings": ["Maker of tea."]
5543
}]
5644
}
5745
}]

0 commit comments

Comments
 (0)