Unified symbol-to-docblock server command
[hiphop-php.git] / hphp / hack / src / server / serverExtractStandalone.ml
blobb857564e2d5b0dab8620d4a60198c99f9930e95d
1 (**
2 * Copyright (c) Facebook, Inc. and its affiliates.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the "hack" directory of this source tree.
7 *)
9 open Typing_defs
10 open Core_kernel
11 open Ast
13 exception FunctionNotFound
15 let extract_function_body func =
16 let fname_pos = match Decl_provider.get_fun func with
17 | Some f -> f.ft_pos
18 | None -> raise FunctionNotFound in
19 let rel_filename = Pos.filename fname_pos in
20 let abs_filename = Pos.filename (Pos.to_absolute fname_pos) in
21 let file_content = In_channel.read_all abs_filename in
22 match Ast_provider.find_fun_in_file rel_filename func with
23 | Some ast_function ->
24 let pos = ast_function.f_span in
25 let include_first_whsp = Pos.merge (Pos.first_char_of_line pos) pos in
26 Pos.get_text_from_pos file_content include_first_whsp
27 | None -> raise FunctionNotFound
29 let go function_name =
30 try extract_function_body function_name with FunctionNotFound -> "Function not found!"