Unified symbol-to-docblock server command
[hiphop-php.git] / hphp / hack / src / server / symbolTypeService.ml
blob8238cc32358f7b18a7c84c31fc10827a673acdbf
1 (**
2 * Copyright (c) 2015, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 open Hh_core
12 open ServerCommandTypes.Symbol_type
14 module Result_set = Set.Make(struct
15 type t = ServerCommandTypes.Symbol_type.t
16 let compare a b = Pos.compare a.pos b.pos
17 end)
19 let visitor = object (self)
20 inherit [_] Tast_visitor.reduce as super
22 method zero = Result_set.empty
23 method plus = Result_set.union
25 method! on_expr env (((pos, ty), expr_) as expr) =
26 let acc =
27 match expr_ with
28 | Tast.Lvar (_, id)
29 | Tast.Dollardollar (_, id) ->
30 Result_set.singleton {
31 pos = Pos.to_relative_string pos;
32 type_ = Tast_env.print_ty env ty;
33 ident_ = Local_id.to_int id
35 | _ -> self#zero
37 self#plus acc @@ super#on_expr env expr
39 method! on_fun_param env param =
40 let acc =
41 let (pos, ty) = param.Tast.param_annotation in
42 Result_set.singleton {
43 pos = Pos.to_relative_string pos;
44 type_ = Tast_env.print_ty env ty;
45 ident_ = Local_id.to_int (Local_id.make_unscoped param.Tast.param_name);
48 self#plus acc @@ super#on_fun_param env param
49 end
51 let generate_types tasts =
52 tasts
53 |> List.map ~f:visitor#go
54 |> List.fold ~init:Result_set.empty ~f:Result_set.union
55 |> Result_set.elements