这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions merlin-lib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ depends: [
"menhirSdk" {dev & = "20231231"}
"yojson" {>= "2.0.0"}
"ppx_yojson_conv" {>= "0.17.0"}
"ppx_jane" {>= "0.17.0"}
]
synopsis:
"Merlin's libraries"
Expand Down
1 change: 1 addition & 0 deletions src/analysis/dune
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
ocaml_parsing
ocaml_preprocess
query_protocol
query_protocol_kernel
ocaml_typing
ocaml_utils
str
Expand Down
5 changes: 2 additions & 3 deletions src/commands/new_commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,8 @@ let all_commands =
"<%s> Which context to search for the identifier in" contexts)
(Marg.param (Format.sprintf "<%s>" contexts)
(fun ctx (prefix, pos, kind, _) ->
match Query_protocol.Locate_context.of_string ctx with
| Some ctx -> (prefix, pos, kind, Some ctx)
| None -> failwithf "invalid context %s." ctx)))
let ctx = Query_protocol.Locate_context.of_string ctx in
(prefix, pos, kind, Some ctx))))
]
~doc:
"Finds the declaration of entity at the specified position, Or \
Expand Down
31 changes: 7 additions & 24 deletions src/commands/query_json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,7 @@ let dump (type a) : a t -> json =
in
let kinds_to_json kind =
`List
(List.map
~f:(function
| `Constructor -> `String "constructor"
| `Keywords -> `String "keywords"
| `Labels -> `String "label"
| `Modules -> `String "module"
| `Modules_type -> `String "module-type"
| `Types -> `String "type"
| `Values -> `String "value"
| `Variants -> `String "variant")
kind)
(List.map ~f:(fun kind -> `String (Compl.In_kind.to_string kind)) kind)
in
function
| Type_expr (expr, pos) ->
Expand Down Expand Up @@ -224,19 +214,12 @@ let dump (type a) : a t -> json =
mk "signature-help" [ ("position", mk_position position) ]
| Version -> mk "version" []

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

let with_location ?(with_file = false) ?(skip_none = false) loc assoc =
let with_file l =
Expand Down
88 changes: 88 additions & 0 deletions src/frontend/kernel/completion_kind.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
module In = struct
type t =
[ `Constructor
| `Labels
| `Modules
| `Modules_type
| `Types
| `Values
| `Variants
| `Keywords ]
[@@deriving enumerate, equal]

let to_string = function
| `Constructor -> "constructor"
| `Keywords -> "keywords"
| `Labels -> "label"
| `Modules -> "module"
| `Modules_type -> "module-type"
| `Types -> "type"
| `Values -> "value"
| `Variants -> "variant"

let of_string_opt = function
| "t" | "type" | "types" -> Some `Types
| "v" | "val" | "value" | "values" -> Some `Values
| "variant" | "variants" | "var" -> Some `Variants
| "c" | "constr" | "constructor" -> Some `Constructor
| "l" | "label" | "labels" -> Some `Labels
| "m" | "mod" | "module" -> Some `Modules
| "mt" | "modtype" | "module-type" -> Some `Modules_type
| "k" | "kw" | "keyword" | "keywords" -> Some `Keywords
| _ -> None
end

module Out = struct
(* CR-someday: This module is necessary because ppx_string_conv doesn't currently
(v0.17.0) support polymorphic variants. *)
module For_deriving = struct
type t =
| Value [@rename "Value"]
| Constructor [@rename "Constructor"]
| Variant [@rename "Variant"]
| Label [@rename "Label"]
| Module [@rename "Module"]
| Modtype [@rename "Signature"]
| Type [@rename "Type"]
| MethodCall [@rename "#"]
| Keyword [@rename "Keyword"]
[@@deriving string]

let to_poly = function
| Value -> `Value
| Constructor -> `Constructor
| Variant -> `Variant
| Label -> `Label
| Module -> `Module
| Modtype -> `Modtype
| Type -> `Type
| MethodCall -> `MethodCall
| Keyword -> `Keyword

let of_poly = function
| `Value -> Value
| `Constructor -> Constructor
| `Variant -> Variant
| `Label -> Label
| `Module -> Module
| `Modtype -> Modtype
| `Type -> Type
| `MethodCall -> MethodCall
| `Keyword -> Keyword
end

type t =
[ `Value
| `Constructor
| `Variant
| `Label
| `Module
| `Modtype
| `Type
| `MethodCall
| `Keyword ]
[@@deriving enumerate, equal]

let to_string x = For_deriving.of_poly x |> For_deriving.to_string
let of_string s = For_deriving.of_string s |> For_deriving.to_poly
end
28 changes: 28 additions & 0 deletions src/frontend/kernel/completion_kind.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module In : sig
type t =
[ `Constructor
| `Labels
| `Modules
| `Modules_type
| `Types
| `Values
| `Variants
| `Keywords ]
[@@deriving to_string, enumerate, equal]

val of_string_opt : string -> t option
end

module Out : sig
type t =
[ `Value
| `Constructor
| `Variant
| `Label
| `Module
| `Modtype
| `Type
| `MethodCall
| `Keyword ]
[@@deriving string, enumerate, equal]
end
2 changes: 1 addition & 1 deletion src/frontend/kernel/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
(name query_protocol_kernel)
(public_name merlin-lib.query_protocol_kernel)
(libraries yojson)
(preprocess (pps ppx_yojson_conv)))
(preprocess (pps ppx_jane ppx_yojson_conv)))
11 changes: 11 additions & 0 deletions src/frontend/kernel/locate_context.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type t =
| Expr [@rename "expr"]
| Module_path [@rename "module_path"]
| Module_type [@rename "module_type"]
| Patt [@rename "pattern"]
| Type [@rename "type"]
| Constant [@rename "constant"]
| Constructor [@rename "constructor"]
| Label [@rename "label"]
| Unknown [@rename "unknown"]
[@@deriving string ~case_insensitive, enumerate]
11 changes: 11 additions & 0 deletions src/frontend/kernel/locate_context.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type t =
| Expr
| Module_path
| Module_type
| Patt
| Type
| Constant
| Constructor
| Label
| Unknown
[@@deriving string, enumerate]
33 changes: 33 additions & 0 deletions src/frontend/kernel/locate_type_multi_result.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(* This module contains definitions that can be used in a js-of-ocaml environment. This
is useful because it allows VSCode extensions (which run in javascript) to use the
serializers/deserializers defined in this module. *)

open Ppx_yojson_conv_lib.Yojson_conv.Primitives

module Lexing = struct
include Lexing

type nonrec position = position =
{ pos_fname : string; pos_lnum : int; pos_bol : int; pos_cnum : int }
[@@deriving yojson]
end

type node_data =
| Arrow
| Tuple
| Object
| Type_ref of
{ type_ : string;
result :
[ `Found of string option * Lexing.position
| `Builtin of string
| `Not_in_env of string
| `File_not_found of string
| `Not_found of string * string option ]
}
[@@deriving yojson]

type type_tree = { data : node_data; children : type_tree list }
[@@deriving yojson]

type t = Success of type_tree | Invalid_context [@@deriving yojson]
19 changes: 19 additions & 0 deletions src/frontend/kernel/locate_type_multi_result.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type node_data =
| Arrow
| Tuple
| Object
| Type_ref of
{ type_ : string;
result :
[ `Found of string option * Lexing.position
| `Builtin of string
| `Not_in_env of string
| `File_not_found of string
| `Not_found of string * string option ]
}
[@@deriving yojson]

type type_tree = { data : node_data; children : type_tree list }
[@@deriving yojson]

type t = Success of type_tree | Invalid_context [@@deriving yojson]
50 changes: 50 additions & 0 deletions src/frontend/kernel/outline_kind.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module For_deriving = struct
type t =
| Value [@rename "Value"]
| Constructor [@rename "Constructor"]
| Label [@rename "Label"]
| Module [@rename "Module"]
| Modtype [@rename "Signature"]
| Type [@rename "Type"]
| Exn [@rename "Exn"]
| Class [@rename "Class"]
| Method [@rename "Method"]
[@@deriving string]

let to_poly = function
| Value -> `Value
| Constructor -> `Constructor
| Label -> `Label
| Module -> `Module
| Modtype -> `Modtype
| Type -> `Type
| Exn -> `Exn
| Class -> `Class
| Method -> `Method

let of_poly = function
| `Value -> Value
| `Constructor -> Constructor
| `Label -> Label
| `Module -> Module
| `Modtype -> Modtype
| `Type -> Type
| `Exn -> Exn
| `Class -> Class
| `Method -> Method
end

type t =
[ `Value
| `Constructor
| `Label
| `Module
| `Modtype
| `Type
| `Exn
| `Class
| `Method ]
[@@deriving equal, enumerate]

let to_string x = For_deriving.of_poly x |> For_deriving.to_string
let of_string s = For_deriving.of_string s |> For_deriving.to_poly
11 changes: 11 additions & 0 deletions src/frontend/kernel/outline_kind.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type t =
[ `Value
| `Constructor
| `Label
| `Module
| `Modtype
| `Type
| `Exn
| `Class
| `Method ]
[@@deriving string, equal, enumerate]
39 changes: 4 additions & 35 deletions src/frontend/kernel/query_protocol_kernel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,7 @@
is useful because it allows VSCode extensions (which run in javascript) to use the
serializers/deserializers defined in this module. *)

open struct
include Ppx_yojson_conv_lib.Yojson_conv.Primitives

module Lexing = struct
include Lexing

type nonrec position = position =
{ pos_fname : string; pos_lnum : int; pos_bol : int; pos_cnum : int }
[@@deriving yojson]
end
end

module Locate_type_multi_result = struct
open Ppx_yojson_conv_lib.Yojson_conv.Primitives

type node_data =
| Arrow
| Tuple
| Object
| Type_ref of
{ type_ : string;
result :
[ `Found of string option * Lexing.position
| `Builtin of string
| `Not_in_env of string
| `File_not_found of string
| `Not_found of string * string option ]
}
[@@deriving yojson]

type type_tree = { data : node_data; children : type_tree list }
[@@deriving yojson]

type t = Success of type_tree | Invalid_context [@@deriving yojson]
end
module Completion_kind = Completion_kind
module Locate_context = Locate_context
module Locate_type_multi_result = Locate_type_multi_result
module Outline_kind = Outline_kind
Loading