Skip to content

Commit 3c376d9

Browse files
committed
Refactor constructor.
1 parent d711587 commit 3c376d9

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

analysis/src/NewCompletions.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ let domLabels =
444444
("suppressContentEditableWarning", "bool");
445445
]
446446

447-
let showConstructor {cname = {txt}; args; res} =
447+
let showConstructor {Constructor.cname = {txt}; args; res} =
448448
txt
449449
^ (match args with
450450
| [] -> ""
@@ -552,13 +552,17 @@ let completionForConstructors ~(env : QueryEnv.t) ~suffix =
552552
match t.item.kind with
553553
| SharedTypes.Type.Variant constructors ->
554554
(constructors
555-
|> List.filter (fun c -> Utils.startsWith c.cname.txt suffix)
555+
|> List.filter (fun c ->
556+
Utils.startsWith c.Constructor.cname.txt suffix)
556557
|> List.map (fun c -> (c, t)))
557558
@ results
558559
| _ -> results)
559560
env.exported.types []
560561
|> List.map (fun (c, t) ->
561-
{(emptyDeclared c.cname.txt) with item = Kind.Constructor (c, t)})
562+
{
563+
(emptyDeclared c.Constructor.cname.txt) with
564+
item = Kind.Constructor (c, t);
565+
})
562566

563567
let completionForFields ~(env : QueryEnv.t) ~suffix =
564568
Hashtbl.fold

analysis/src/ProcessCmt.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ let rec forTypeSignatureItem ~env ~(exported : SharedTypes.Exported.t)
8181
let stamp = Ident.binding_time cd_id in
8282
let item =
8383
{
84-
stamp;
84+
Constructor.stamp;
8585
cname = Location.mknoloc name;
8686
args =
8787
(match cd_args with
@@ -189,7 +189,7 @@ let forTypeDeclaration ~env ~(exported : Exported.t)
189189
|> List.map (fun {cd_id; cd_name = cname; cd_args; cd_res} ->
190190
let stamp = Ident.binding_time cd_id in
191191
{
192-
stamp;
192+
Constructor.stamp;
193193
cname;
194194
args =
195195
(match cd_args with
@@ -579,9 +579,9 @@ let extraForFile ~(file : File.t) =
579579
addLocItem extra fname.loc
580580
(Typed
581581
(d.name.txt, typ, Definition (d.stamp, Field fname.txt))))
582-
| Variant constructos ->
583-
constructos
584-
|> List.iter (fun {stamp; cname} ->
582+
| Variant constructors ->
583+
constructors
584+
|> List.iter (fun {Constructor.stamp; cname} ->
585585
addReference stamp cname.loc;
586586
let t =
587587
{
@@ -825,7 +825,8 @@ struct
825825
match t with
826826
| `Local {stamp; item = {kind = Variant constructors}} -> (
827827
match
828-
constructors |> List.find_opt (fun c -> c.cname.txt = cstr_name)
828+
constructors
829+
|> List.find_opt (fun c -> c.Constructor.cname.txt = cstr_name)
829830
with
830831
| Some {stamp = cstamp} ->
831832
addReference cstamp nameLoc;

analysis/src/References.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ let getConstructor (file : File.t) stamp name =
115115
match kind with
116116
| Variant constructors -> (
117117
match
118-
constructors |> List.find_opt (fun const -> const.cname.txt = name)
118+
constructors
119+
|> List.find_opt (fun const -> const.Constructor.cname.txt = name)
119120
with
120121
| None -> None
121122
| Some const -> Some const)

analysis/src/SharedTypes.ml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ type visibilityPath =
66

77
type field = {stamp : int; fname : string Location.loc; typ : Types.type_expr}
88

9-
type constructor = {
10-
stamp : int;
11-
cname : string Location.loc;
12-
args : (Types.type_expr * Location.t) list;
13-
res : Types.type_expr option;
14-
}
9+
module Constructor = struct
10+
type t = {
11+
stamp : int;
12+
cname : string Location.loc;
13+
args : (Types.type_expr * Location.t) list;
14+
res : Types.type_expr option;
15+
}
16+
end
1517

1618
module Type = struct
1719
type kind =
1820
| Abstract of (Path.t * Types.type_expr list) option
1921
| Open
2022
| Tuple of Types.type_expr list
2123
| Record of field list
22-
| Variant of constructor list
24+
| Variant of Constructor.t list
2325

2426
type t = {kind : kind; decl : Types.type_declaration}
2527
end
@@ -75,7 +77,7 @@ module Kind = struct
7577
| Module of ModuleKind.t
7678
| Value of Types.type_expr
7779
| Type of Type.t
78-
| Constructor of constructor * Type.t declared
80+
| Constructor of Constructor.t * Type.t declared
7981
| Field of field * Type.t declared
8082
| FileModule of string
8183

@@ -94,7 +96,7 @@ module Stamps = struct
9496
types : Type.t declared stampMap;
9597
values : Types.type_expr declared stampMap;
9698
modules : ModuleKind.t declared stampMap;
97-
constructors : constructor declared stampMap;
99+
constructors : Constructor.t declared stampMap;
98100
}
99101

100102
let init () =

0 commit comments

Comments
 (0)