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.
12 public
function foo
(Bar $b
) : int {
13 return $b
->toString
();
17 function f1
(Foo $x
) : void
{ }
18 function f2
(foo $x
) : void
{ }
24 public
function toString
() : string {
31 ctx
: Provider_context.t
;
32 foo_path
: Relative_path.t
;
34 bar_path
: Relative_path.t
;
36 nonexistent_path
: Relative_path.t
;
37 naming_table
: Naming_table.t
;
40 let fake_dir = Filename.concat
Sys_utils.temp_dir_name
"fake"
42 let in_fake_dir path
= Filename.concat
fake_dir path
44 (** This lays down some files on disk. Sets up a forward naming table.
45 Sets up the provider's reverse naming table. Returns an empty context, plus
46 information about the files on disk. The [sqlite] flag determines
47 whether we return a ctx where the naming table is backed by sqlite, or
49 let setup ~
(sqlite
: bool) (tcopt
: GlobalOptions.t
) : setup =
50 (* Set up a simple fake repo *)
51 Disk.mkdir_p
@@ in_fake_dir "root/";
52 Relative_path.set_path_prefix
54 (Path.make
@@ in_fake_dir "root/");
56 (* We'll need to parse these files in order to create a naming table, which
57 will be used for look up of symbols in type checking. *)
58 Disk.write_file ~file
:(in_fake_dir "root/Foo.php") ~contents
:foo_contents;
59 Disk.write_file ~file
:(in_fake_dir "root/Bar.php") ~contents
:bar_contents;
60 let foo_path = Relative_path.from_root ~suffix
:"Foo.php" in
61 let bar_path = Relative_path.from_root ~suffix
:"Bar.php" in
62 let nonexistent_path = Relative_path.from_root ~suffix
:"Nonexistent.php" in
63 (* Parsing produces the file infos that the naming table module can use
64 to construct the forward naming table (files-to-symbols) *)
65 let popt = ParserOptions.default
in
66 let deps_mode = Typing_deps_mode.SQLiteMode
in
68 Provider_context.empty_for_tool
71 ~backend
:(Provider_backend.get
())
74 let (file_infos
, _errors
, _failed_parsing
) =
78 Relative_path.Set.empty
79 ~get_next
:(MultiWorker.next None
[foo_path; bar_path])
83 let naming_table = Naming_table.create file_infos
in
84 (* Construct the reverse naming table (symbols-to-files) *)
85 let fast = Naming_table.to_fast
naming_table in
86 Relative_path.Map.iter
88 ~f
:(fun (name
: Relative_path.t
) (info
: FileInfo.names
) ->
89 Naming_global.ndecl_file_fast
92 ~funs
:info
.FileInfo.n_funs
93 ~classes
:info
.FileInfo.n_classes
94 ~record_defs
:info
.FileInfo.n_record_defs
95 ~typedefs
:info
.FileInfo.n_types
96 ~consts
:info
.FileInfo.n_consts
);
98 let (ctx, naming_table) =
100 let db_name = Filename.temp_file
"server_naming" ".sqlite" in
101 let (_save_result
: Naming_sqlite.save_result
) =
102 Naming_table.save
naming_table db_name
104 (* Now, I want a fresh ctx with no reverse-naming entries in it,
105 and I want it to be backed by a sqlite naming database. *)
106 Provider_backend.set_local_memory_backend_with_defaults
();
108 Provider_context.empty_for_tool
109 ~
popt:(Provider_context.get_popt
ctx)
110 ~tcopt
:(Provider_context.get_tcopt
ctx)
111 ~backend
:(Provider_backend.get
())
112 ~
deps_mode:(Provider_context.get_deps_mode
ctx)
114 (sqlite_ctx, Naming_table.load_from_sqlite
sqlite_ctx db_name)