Skip to content

Commit b6a4d25

Browse files
committed
Refactor query_protocol
1 parent e46b24b commit b6a4d25

File tree

13 files changed

+128
-107
lines changed

13 files changed

+128
-107
lines changed

merlin-lib.opam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ depends: [
1919
"menhirSdk" {dev & = "20231231"}
2020
"yojson" {>= "2.0.0"}
2121
"ppx_yojson_conv" {>= "0.17.0"}
22+
"ppx_jane" {>= "0.17.0"}
2223
]
2324
synopsis:
2425
"Merlin's libraries"

src/analysis/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
ocaml_parsing
2424
ocaml_preprocess
2525
query_protocol
26+
query_protocol_kernel
2627
ocaml_typing
2728
ocaml_utils
2829
str

src/commands/new_commands.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,8 @@ let all_commands =
480480
"<%s> Which context to search for the identifier in" contexts)
481481
(Marg.param (Format.sprintf "<%s>" contexts)
482482
(fun ctx (prefix, pos, kind, _) ->
483-
match Query_protocol.Locate_context.of_string ctx with
484-
| Some ctx -> (prefix, pos, kind, Some ctx)
485-
| None -> failwithf "invalid context %s." ctx)))
483+
let ctx = Query_protocol.Locate_context.of_string ctx in
484+
(prefix, pos, kind, Some ctx))))
486485
]
487486
~doc:
488487
"Finds the declaration of entity at the specified position, Or \

src/commands/query_json.ml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,7 @@ 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
43-
(List.map
44-
~f:(function
45-
| `Constructor -> `String "constructor"
46-
| `Keywords -> `String "keywords"
47-
| `Labels -> `String "label"
48-
| `Modules -> `String "module"
49-
| `Modules_type -> `String "module-type"
50-
| `Types -> `String "type"
51-
| `Values -> `String "value"
52-
| `Variants -> `String "variant")
53-
kind)
42+
`List (List.map ~f:(fun kind -> `String (Compl.Kind.to_string kind)) kind)
5443
in
5544
function
5645
| Type_expr (expr, pos) ->
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
type t =
2+
[ `Constructor
3+
| `Labels
4+
| `Modules
5+
| `Modules_type
6+
| `Types
7+
| `Values
8+
| `Variants
9+
| `Keywords ]
10+
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"
20+
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
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type t =
2+
[ `Constructor
3+
| `Labels
4+
| `Modules
5+
| `Modules_type
6+
| `Types
7+
| `Values
8+
| `Variants
9+
| `Keywords ]
10+
11+
val to_string : t -> string
12+
val of_string_opt : string -> t option

src/frontend/kernel/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
(name query_protocol_kernel)
33
(public_name merlin-lib.query_protocol_kernel)
44
(libraries yojson)
5-
(preprocess (pps ppx_yojson_conv)))
5+
(preprocess (pps ppx_jane ppx_yojson_conv)))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type t =
2+
| Expr [@rename "expr"]
3+
| Module_path [@rename "module_path"]
4+
| Module_type [@rename "module_type"]
5+
| Patt [@rename "pattern"]
6+
| Type [@rename "type"]
7+
| Constant [@rename "constant"]
8+
| Constructor [@rename "constructor"]
9+
| Label [@rename "label"]
10+
| Unknown [@rename "unknown"]
11+
[@@deriving string ~case_insensitive, enumerate]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type t =
2+
| Expr
3+
| Module_path
4+
| Module_type
5+
| Patt
6+
| Type
7+
| Constant
8+
| Constructor
9+
| Label
10+
| Unknown
11+
[@@deriving string, enumerate]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(* This module contains definitions that can be used in a js-of-ocaml environment. This
2+
is useful because it allows VSCode extensions (which run in javascript) to use the
3+
serializers/deserializers defined in this module. *)
4+
5+
open Ppx_yojson_conv_lib.Yojson_conv.Primitives
6+
7+
module Lexing = struct
8+
include Lexing
9+
10+
type nonrec position = position =
11+
{ pos_fname : string; pos_lnum : int; pos_bol : int; pos_cnum : int }
12+
[@@deriving yojson]
13+
end
14+
15+
type node_data =
16+
| Arrow
17+
| Tuple
18+
| Object
19+
| Type_ref of
20+
{ type_ : string;
21+
result :
22+
[ `Found of string option * Lexing.position
23+
| `Builtin of string
24+
| `Not_in_env of string
25+
| `File_not_found of string
26+
| `Not_found of string * string option ]
27+
}
28+
[@@deriving yojson]
29+
30+
type type_tree = { data : node_data; children : type_tree list }
31+
[@@deriving yojson]
32+
33+
type t = Success of type_tree | Invalid_context [@@deriving yojson]

0 commit comments

Comments
 (0)