Skip to content

Commit 6e5d291

Browse files
committed
fix encoding bug
1 parent 9c17c78 commit 6e5d291

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

ocaml-lsp-server/src/custom_requests/req_type_search.ml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
open Import
2-
module TextDocumentPositionParams = Lsp.Types.TextDocumentPositionParams
32

43
let meth = "ocamllsp/typeSearch"
54
let capability = "handleTypeSearch", `Bool true
@@ -15,21 +14,19 @@ module TypeSearchParams = struct
1514

1615
let t_of_yojson json =
1716
let open Yojson.Safe.Util in
18-
let textDocumentPosition = Lsp.Types.TextDocumentPositionParams.t_of_yojson json in
1917
let query = json |> member "query" |> to_string in
2018
let limit = json |> member "limit" |> to_int in
2119
let with_doc = json |> member "with_doc" |> to_bool in
22-
{ position = textDocumentPosition.position
23-
; text_document = textDocumentPosition.textDocument
24-
; query
25-
; limit
26-
; with_doc
27-
}
20+
let position = json |> member "position" |> Position.t_of_yojson in
21+
let text_document =
22+
json |> member "text_document" |> TextDocumentIdentifier.t_of_yojson
23+
in
24+
{ text_document; position; query; limit; with_doc }
2825
;;
2926

3027
let yojson_of_t { text_document; position; query; limit; with_doc } =
3128
`Assoc
32-
(("textDocument", TextDocumentIdentifier.yojson_of_t text_document)
29+
(("text_document", TextDocumentIdentifier.yojson_of_t text_document)
3330
:: ("position", Position.yojson_of_t position)
3431
:: ("limit", `Int limit)
3532
:: ("with_doc", `Bool with_doc)
@@ -65,7 +62,7 @@ module Request_params = struct
6562

6663
let yojson_of_t t = TypeSearchParams.yojson_of_t t
6764

68-
let create text_document position limit query with_doc : t =
65+
let create ~text_document ~position ?(limit = 20) ~query ?(with_doc = true) () : t =
6966
{ text_document; position; limit; query; with_doc }
7067
;;
7168
end
@@ -82,6 +79,8 @@ let on_request ~params state =
8279
Fiber.of_thunk (fun () ->
8380
let params = (Option.value ~default:(`Assoc []) params :> Yojson.Safe.t) in
8481
let TypeSearchParams.{ text_document; position; limit; query; with_doc } =
82+
let json_str = Yojson.Safe.pretty_to_string params in
83+
Format.printf "%s@." json_str;
8584
TypeSearchParams.t_of_yojson params
8685
in
8786
let uri = text_document.uri in

ocaml-lsp-server/src/custom_requests/req_type_search.mli

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ module Request_params : sig
44
type t
55

66
val yojson_of_t : t -> Json.t
7-
val create : TextDocumentIdentifier.t -> Position.t -> int -> string -> bool -> t
7+
8+
val create
9+
: text_document:TextDocumentIdentifier.t
10+
-> position:Position.t
11+
-> ?limit:int
12+
-> query:string
13+
-> ?with_doc:bool
14+
-> unit
15+
-> t
816
end
917

1018
type t

ocaml-lsp-server/test/e2e-new/type_search.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Util = struct
66
let uri = DocumentUri.of_path "test.ml" in
77
let text_document = TextDocumentIdentifier.create ~uri in
88
let params =
9-
Req.Request_params.create text_document position 3 query with_doc
9+
Req.Request_params.create ~text_document ~position ~limit:3 ~query ~with_doc ()
1010
|> Req.Request_params.yojson_of_t
1111
|> Jsonrpc.Structured.t_of_yojson
1212
|> Option.some

0 commit comments

Comments
 (0)