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.
13 exception FunctionNotFound
15 let extract_function_body func
=
16 let fname_pos = match Decl_provider.get_fun func
with
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!"