@@ -19,42 +19,39 @@ module JumpParams = struct
1919 type t =
2020 { textDocument : TextDocumentIdentifier .t
2121 ; position : Position .t
22+ ; target : string option
2223 }
2324
2425 let t_of_yojson json =
2526 let open Yojson.Safe.Util in
2627 { textDocument = json |> member " textDocument" |> TextDocumentIdentifier. t_of_yojson
2728 ; position = json |> member " position" |> Position. t_of_yojson
29+ ; target = json |> member " target" |> to_string_option
2830 }
2931 ;;
3032
31- let yojson_of_t { textDocument; position } =
33+ let yojson_of_t { textDocument; position; target } =
34+ let target =
35+ Option. value_map target ~default: [] ~f: (fun v -> [ " target" , `String v ])
36+ in
3237 `Assoc
33- [ " textDocument" , TextDocumentIdentifier. yojson_of_t textDocument
34- ; " position" , Position. yojson_of_t position
35- ]
38+ (( " textDocument" , TextDocumentIdentifier. yojson_of_t textDocument)
39+ :: ( " position" , Position. yojson_of_t position)
40+ :: target)
3641 ;;
3742end
3843
3944module Jump = struct
4045 type t = (string * Position .t ) list
4146
42- let yojson_of_t (lst : t ) : Yojson.Safe.t option =
43- if List. is_empty lst
44- then None
45- else
46- Some
47- (`Assoc
48- [ ( " jumps"
49- , `List
50- (List. map
51- ~f: (fun (target , position ) ->
52- `Assoc
53- [ " target" , `String target
54- ; " position" , Position. yojson_of_t position
55- ])
56- lst) )
57- ])
47+ let yojson_of_t (lst : t ) : Yojson.Safe.t =
48+ let jumps =
49+ List. map
50+ ~f: (fun (target , position ) ->
51+ `Assoc [ " target" , `String target; " position" , Position. yojson_of_t position ])
52+ lst
53+ in
54+ `Assoc [ " jumps" , `List jumps ]
5855 ;;
5956end
6057
@@ -65,8 +62,8 @@ module Request_params = struct
6562
6663 let yojson_of_t t = JumpParams. yojson_of_t t
6764
68- let create ~uri ~position =
69- { JumpParams. textDocument = TextDocumentIdentifier. create ~uri ; position }
65+ let create ~uri ~position ~ target =
66+ { JumpParams. textDocument = TextDocumentIdentifier. create ~uri ; position; target }
7067 ;;
7168end
7269
@@ -78,27 +75,30 @@ let dispatch ~merlin ~position ~target =
7875;;
7976
8077let on_request ~params state =
78+ let open Fiber.O in
8179 Fiber. of_thunk (fun () ->
8280 let params = (Option. value ~default: (`Assoc [] ) params :> Yojson.Safe. t) in
8381 let params = JumpParams. t_of_yojson params in
8482 let uri = params.textDocument.uri in
8583 let position = params.position in
8684 let doc = Document_store. get state.State. store uri in
87- let targets = JumpParams. targets in
8885 match Document. kind doc with
8986 | `Other -> Fiber. return `Null
9087 | `Merlin merlin ->
91- Fiber. map
92- (Fiber. parallel_map targets ~f: (fun target ->
93- dispatch ~merlin ~position ~target
94- |> Fiber. map ~f: (function
95- | `Error _ -> None
96- | `Found pos ->
97- (match Position. of_lexical_position pos with
98- | None -> None
99- | Some position -> Some (target, position)))))
100- ~f: (fun results ->
101- match List. filter_map results ~f: Fun. id with
102- | [] -> `Null
103- | lst -> Jump. yojson_of_t lst |> Option. value ~default: `Null ))
88+ let targets =
89+ match params.target with
90+ | None -> JumpParams. targets
91+ | Some target -> [ target ]
92+ in
93+ let + results =
94+ Fiber. parallel_map targets ~f: (fun target ->
95+ dispatch ~merlin ~position ~target
96+ |> Fiber. map ~f: (function
97+ | `Error _ -> None
98+ | `Found pos ->
99+ (match Position. of_lexical_position pos with
100+ | None -> None
101+ | Some position -> Some (target, position))))
102+ in
103+ Jump. yojson_of_t (List. filter_map results ~f: Fun. id))
104104;;
0 commit comments