Autocomplete global symbol table generator app
[hiphop-php.git] / hphp / hack / src / facts / symbols / textIndexWriter.ml
blobd2c557e0e1c21eb44a75fb4721eacc2eba93d088
1 (**
2 * Copyright (c) 2019, 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 IndexBuilderTypes
13 let record_in_textfile
14 (filename: string)
15 (symbols: found_symbol_result list): unit =
17 (* Open a temporary file *)
18 let open Core_kernel in
19 let temp_filename = filename ^ ".temp" in
20 let channel = Out_channel.create temp_filename in
22 (* Write lines to file *)
23 List.iter symbols ~f:(fun symbol -> begin
24 let kindstr = Printf.sprintf "%d" (kind_to_int symbol.found_symbol_kind) in
25 Out_channel.output_string channel symbol.found_symbol_name;
26 Out_channel.output_string channel " ";
27 Out_channel.output_string channel kindstr;
28 Out_channel.output_string channel "\n";
29 end);
31 (* Clean up *)
32 Out_channel.close channel;
34 (* Sort the file *)
35 let cmdline = Printf.sprintf "sort -f \"%s\" -o \"%s\""
36 temp_filename filename in
37 let _ = Unix.system cmdline in
38 Sys.remove filename;