JSON RPC version of autocomplete / didOpenFile messages
[hiphop-php.git] / hphp / hack / src / ide_rpc / ide_rpc_V0_message_printer.ml
blobc8d2a8ae65bf786e76778d5b9c60414f6f2d5881
1 (**
2 * Copyright (c) 2016, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the "hack" directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
9 *)
11 open Core
12 open Ide_message
13 open Hh_json
15 let autocomplete_response_to_json x =
16 let param_to_json x = JSON_Object [
17 ("name", JSON_String x.name);
18 ("type", JSON_String x.type_);
19 ] in
21 let callable_details_to_json x = JSON_Object [
22 ("return_type", JSON_String x.return_type);
23 ("params", JSON_Array (List.map x.params ~f:param_to_json));
24 ] in
26 let callable_details_to_json = function
27 | None -> []
28 | Some x -> [("callable_details", callable_details_to_json x)] in
30 let autocomplete_response_to_json x = JSON_Object ([
31 ("name", JSON_String x.autocomplete_item_text);
32 ("type", JSON_String x.autocomplete_item_type);
33 ] @ (callable_details_to_json x.callable_details)) in
35 JSON_Array (List.map x ~f:autocomplete_response_to_json)
37 let to_json ~id:_ ~response =
38 match response with
39 | Autocomplete_response x -> autocomplete_response_to_json x
40 (* Delegate unhandled messages to previous version of API *)
41 | _ -> Nuclide_rpc_message_printer.to_json ~response