2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
11 open ServerCommandTypes.Symbol_info_service
13 (* This module dumps all the symbol info(like fun-calls) in input files *)
15 let recheck_naming filename_l
=
16 List.iter filename_l
begin fun file
->
17 Errors.ignore_
begin fun () ->
18 (* We only need to name to find references to locals *)
19 List.iter
(Ast_provider.get_ast file
) begin function
21 let _ = Naming.fun_
(Ast_to_nast.on_fun f
) in
24 let _ = Naming.class_
(Ast_to_nast.on_class c
) in
31 let helper tcopt acc filetuple_l
=
32 let filename_l = List.rev_map filetuple_l fst
in
33 recheck_naming filename_l;
34 let tasts = ServerIdeUtils.recheck tcopt filetuple_l
|> List.map ~f
:snd
in
35 let fun_calls = SymbolFunCallService.find_fun_calls
tasts in
36 let symbol_types = SymbolTypeService.generate_types
tasts in
37 (fun_calls, symbol_types) :: acc
39 let parallel_helper workers filetuple_l tcopt
=
44 ~merge
:List.rev_append
45 ~next
:(MultiWorker.next workers filetuple_l
)
47 (* Format result from '(fun_calls * symbol_types) list' raw result into *)
48 (* 'fun_calls list, symbol_types list' and store in SymbolInfoService.result *)
49 let format_result raw_result
=
50 let result_list = List.fold_left raw_result ~f
:begin fun acc bucket
->
51 let result1, result2
= acc
in
52 let part1, part2
= bucket
in
53 (List.rev_append
part1 result1,
54 List.rev_append part2 result2
)
57 fun_calls = fst
result_list;
58 symbol_types = snd
result_list;
62 let go workers file_list env
=
63 (* Convert 'string list' into 'fileinfo list' *)
64 let filetuple_l = List.fold_left file_list ~f
:begin fun acc file_path
->
65 let fn = Relative_path.create
Relative_path.Root file_path
in
66 match Naming_table.get_file_info env
.ServerEnv.naming_table
fn with
67 | Some fileinfo
-> (fn, fileinfo
) :: acc
71 let tcopt = env
.ServerEnv.tcopt in
73 if (List.length file_list
) < 10 then
74 helper tcopt [] filetuple_l
76 parallel_helper workers
filetuple_l tcopt in
77 format_result raw_result