Skip to content

Commit ba8a21f

Browse files
committed
Move more types to kernel
1 parent b6a4d25 commit ba8a21f

File tree

7 files changed

+189
-75
lines changed

7 files changed

+189
-75
lines changed

src/commands/query_json.ml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ let dump (type a) : a t -> json =
3939
`Assoc [ ("line", `Int line); ("column", `Int col) ]
4040
in
4141
let kinds_to_json kind =
42-
`List (List.map ~f:(fun kind -> `String (Compl.Kind.to_string kind)) kind)
42+
`List
43+
(List.map ~f:(fun kind -> `String (Compl.In_kind.to_string kind)) kind)
4344
in
4445
function
4546
| Type_expr (expr, pos) ->
@@ -212,19 +213,12 @@ let dump (type a) : a t -> json =
212213
mk "signature-help" [ ("position", mk_position position) ]
213214
| Version -> mk "version" []
214215

215-
let string_of_completion_kind = function
216-
| `Value -> "Value"
217-
| `Variant -> "Variant"
218-
| `Constructor -> "Constructor"
219-
| `Label -> "Label"
220-
| `Module -> "Module"
221-
| `Modtype -> "Signature"
222-
| `Type -> "Type"
223-
| `Method -> "Method"
224-
| `MethodCall -> "#"
225-
| `Exn -> "Exn"
226-
| `Class -> "Class"
227-
| `Keyword -> "Keyword"
216+
let string_of_completion_kind =
217+
(* Merlin-jst: In upstream Merlin, the to_string logic lives here. But in Merlin-jst,
218+
we've moved it to query_protocol_kernel so that it can be used in jsoo contexts *)
219+
function
220+
| #Compl.Out_kind.t as kind -> Compl.Out_kind.to_string kind
221+
| #Outline_kind.t as kind -> Outline_kind.to_string kind
228222

229223
let with_location ?(with_file = false) ?(skip_none = false) loc assoc =
230224
let with_file l =
Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,88 @@
1-
type t =
2-
[ `Constructor
3-
| `Labels
4-
| `Modules
5-
| `Modules_type
6-
| `Types
7-
| `Values
8-
| `Variants
9-
| `Keywords ]
1+
module In = struct
2+
type t =
3+
[ `Constructor
4+
| `Labels
5+
| `Modules
6+
| `Modules_type
7+
| `Types
8+
| `Values
9+
| `Variants
10+
| `Keywords ]
11+
[@@deriving enumerate, equal]
1012

11-
let to_string = function
12-
| `Constructor -> "constructor"
13-
| `Keywords -> "keywords"
14-
| `Labels -> "label"
15-
| `Modules -> "module"
16-
| `Modules_type -> "module-type"
17-
| `Types -> "type"
18-
| `Values -> "value"
19-
| `Variants -> "variant"
13+
let to_string = function
14+
| `Constructor -> "constructor"
15+
| `Keywords -> "keywords"
16+
| `Labels -> "label"
17+
| `Modules -> "module"
18+
| `Modules_type -> "module-type"
19+
| `Types -> "type"
20+
| `Values -> "value"
21+
| `Variants -> "variant"
2022

21-
let of_string_opt = function
22-
| "t" | "type" | "types" -> Some `Types
23-
| "v" | "val" | "value" | "values" -> Some `Values
24-
| "variant" | "variants" | "var" -> Some `Variants
25-
| "c" | "constr" | "constructor" -> Some `Constructor
26-
| "l" | "label" | "labels" -> Some `Labels
27-
| "m" | "mod" | "module" -> Some `Modules
28-
| "mt" | "modtype" | "module-type" -> Some `Modules_type
29-
| "k" | "kw" | "keyword" | "keywords" -> Some `Keywords
30-
| _ -> None
23+
let of_string_opt = function
24+
| "t" | "type" | "types" -> Some `Types
25+
| "v" | "val" | "value" | "values" -> Some `Values
26+
| "variant" | "variants" | "var" -> Some `Variants
27+
| "c" | "constr" | "constructor" -> Some `Constructor
28+
| "l" | "label" | "labels" -> Some `Labels
29+
| "m" | "mod" | "module" -> Some `Modules
30+
| "mt" | "modtype" | "module-type" -> Some `Modules_type
31+
| "k" | "kw" | "keyword" | "keywords" -> Some `Keywords
32+
| _ -> None
33+
end
34+
35+
module Out = struct
36+
(* CR-someday: This module is necessary because ppx_string_conv doesn't currently
37+
(v0.17.0) support polymorphic variants. *)
38+
module For_deriving = struct
39+
type t =
40+
| Value [@rename "Value"]
41+
| Constructor [@rename "Constructor"]
42+
| Variant [@rename "Variant"]
43+
| Label [@rename "Label"]
44+
| Module [@rename "Module"]
45+
| Modtype [@rename "Signature"]
46+
| Type [@rename "Type"]
47+
| MethodCall [@rename "#"]
48+
| Keyword [@rename "Keyword"]
49+
[@@deriving string]
50+
51+
let to_poly = function
52+
| Value -> `Value
53+
| Constructor -> `Constructor
54+
| Variant -> `Variant
55+
| Label -> `Label
56+
| Module -> `Module
57+
| Modtype -> `Modtype
58+
| Type -> `Type
59+
| MethodCall -> `MethodCall
60+
| Keyword -> `Keyword
61+
62+
let of_poly = function
63+
| `Value -> Value
64+
| `Constructor -> Constructor
65+
| `Variant -> Variant
66+
| `Label -> Label
67+
| `Module -> Module
68+
| `Modtype -> Modtype
69+
| `Type -> Type
70+
| `MethodCall -> MethodCall
71+
| `Keyword -> Keyword
72+
end
73+
74+
type t =
75+
[ `Value
76+
| `Constructor
77+
| `Variant
78+
| `Label
79+
| `Module
80+
| `Modtype
81+
| `Type
82+
| `MethodCall
83+
| `Keyword ]
84+
[@@deriving enumerate, equal]
85+
86+
let to_string x = For_deriving.of_poly x |> For_deriving.to_string
87+
let of_string s = For_deriving.of_string s |> For_deriving.to_poly
88+
end
Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
type t =
2-
[ `Constructor
3-
| `Labels
4-
| `Modules
5-
| `Modules_type
6-
| `Types
7-
| `Values
8-
| `Variants
9-
| `Keywords ]
1+
module In : sig
2+
type t =
3+
[ `Constructor
4+
| `Labels
5+
| `Modules
6+
| `Modules_type
7+
| `Types
8+
| `Values
9+
| `Variants
10+
| `Keywords ]
11+
[@@deriving to_string, enumerate, equal]
1012

11-
val to_string : t -> string
12-
val of_string_opt : string -> t option
13+
val of_string_opt : string -> t option
14+
end
15+
16+
module Out : sig
17+
type t =
18+
[ `Value
19+
| `Constructor
20+
| `Variant
21+
| `Label
22+
| `Module
23+
| `Modtype
24+
| `Type
25+
| `MethodCall
26+
| `Keyword ]
27+
[@@deriving string, enumerate, equal]
28+
end
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module For_deriving = struct
2+
type t =
3+
| Value [@rename "Value"]
4+
| Constructor [@rename "Constructor"]
5+
| Label [@rename "Label"]
6+
| Module [@rename "Module"]
7+
| Modtype [@rename "Signature"]
8+
| Type [@rename "Type"]
9+
| Exn [@rename "Exn"]
10+
| Class [@rename "Class"]
11+
| Method [@rename "Method"]
12+
[@@deriving string]
13+
14+
let to_poly = function
15+
| Value -> `Value
16+
| Constructor -> `Constructor
17+
| Label -> `Label
18+
| Module -> `Module
19+
| Modtype -> `Modtype
20+
| Type -> `Type
21+
| Exn -> `Exn
22+
| Class -> `Class
23+
| Method -> `Method
24+
25+
let of_poly = function
26+
| `Value -> Value
27+
| `Constructor -> Constructor
28+
| `Label -> Label
29+
| `Module -> Module
30+
| `Modtype -> Modtype
31+
| `Type -> Type
32+
| `Exn -> Exn
33+
| `Class -> Class
34+
| `Method -> Method
35+
end
36+
37+
type t =
38+
[ `Value
39+
| `Constructor
40+
| `Label
41+
| `Module
42+
| `Modtype
43+
| `Type
44+
| `Exn
45+
| `Class
46+
| `Method ]
47+
[@@deriving equal, enumerate]
48+
49+
let to_string x = For_deriving.of_poly x |> For_deriving.to_string
50+
let of_string s = For_deriving.of_string s |> For_deriving.to_poly
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type t =
2+
[ `Value
3+
| `Constructor
4+
| `Label
5+
| `Module
6+
| `Modtype
7+
| `Type
8+
| `Exn
9+
| `Class
10+
| `Method ]
11+
[@@deriving string, equal, enumerate]

src/frontend/kernel/query_protocol_kernel.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
module Completion_kind = Completion_kind
66
module Locate_context = Locate_context
77
module Locate_type_multi_result = Locate_type_multi_result
8+
module Outline_kind = Outline_kind

src/frontend/query_protocol.ml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,11 @@
2929
include Query_protocol_kernel
3030

3131
module Compl = struct
32+
module Out_kind = Completion_kind.Out
33+
3234
type 'desc raw_entry =
3335
{ name : string;
34-
kind :
35-
[ `Value
36-
| `Constructor
37-
| `Variant
38-
| `Label
39-
| `Module
40-
| `Modtype
41-
| `Type
42-
| `MethodCall
43-
| `Keyword ];
36+
kind : Out_kind.t;
4437
desc : 'desc;
4538
info : 'desc;
4639
deprecated : bool
@@ -56,8 +49,8 @@ module Compl = struct
5649
context : [ `Unknown | `Application of application_context ]
5750
}
5851

59-
module Kind = Completion_kind
60-
type kind = Kind.t
52+
module In_kind = Completion_kind.In
53+
type kind = In_kind.t
6154
end
6255

6356
type completions = Compl.t
@@ -74,16 +67,7 @@ type 'a type_search_result =
7467
type outline = item list
7568
and item =
7669
{ outline_name : string;
77-
outline_kind :
78-
[ `Value
79-
| `Constructor
80-
| `Label
81-
| `Module
82-
| `Modtype
83-
| `Type
84-
| `Exn
85-
| `Class
86-
| `Method ];
70+
outline_kind : Outline_kind.t;
8771
outline_type : string option;
8872
deprecated : bool;
8973
location : Location_aux.t;

0 commit comments

Comments
 (0)