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.
10 module PositionedSyntaxTree
=
11 Full_fidelity_syntax_tree.WithSyntax
(Full_fidelity_positioned_syntax
)
14 file_input
: ServerCommandTypes.file_input
;
15 path
: Relative_path.t
;
16 source_text
: Full_fidelity_source_text.t
;
17 comments
: Parser_return.comments
;
20 mutable cst
: PositionedSyntaxTree.t
option;
21 mutable tast
: Tast.program
option;
22 mutable tast_errors
: Errors.t
option;
23 mutable symbols
: Relative_path.t
SymbolOccurrence.t list
option;
27 tcopt
: TypecheckerOptions.t
;
28 backend
: Provider_backend.t
;
29 entries
: entry
Relative_path.Map.t
;
32 let empty_for_tool ~tcopt ~backend
=
33 { tcopt
; backend
; entries
= Relative_path.Map.empty
}
35 let empty_for_worker ~tcopt
=
38 backend
= Provider_backend.Shared_memory
;
39 entries
= Relative_path.Map.empty
;
42 let empty_for_test ~tcopt
=
45 backend
= Provider_backend.Shared_memory
;
46 entries
= Relative_path.Map.empty
;
49 let empty_for_debugging ~tcopt
=
52 backend
= Provider_backend.Shared_memory
;
53 entries
= Relative_path.Map.empty
;
56 let map_tcopt (t
: t
) ~
(f
: TypecheckerOptions.t
-> TypecheckerOptions.t
) : t
=
57 { t
with tcopt
= f t
.tcopt
}
59 let global_context : t
option ref = ref None
61 let get_file_input ~
(ctx
: t
) ~
(path
: Relative_path.t
) :
62 ServerCommandTypes.file_input
=
63 match Relative_path.Map.find_opt ctx
.entries path
with
64 | Some
{ file_input
; _
} -> file_input
65 | None
-> ServerCommandTypes.FileName
(Relative_path.to_absolute path
)
67 let get_fileinfo ~
(entry
: entry
) : FileInfo.t
=
68 let (funs
, classes
, record_defs
, typedefs
, consts
) =
69 Nast.get_defs entry
.ast
80 let get_global_context () : t
option = !global_context
82 let set_global_context_internal (t
: t
) : unit =
83 match !global_context with
85 failwith
"set_global_context_internal: a global context is already set"
86 | None
-> global_context := Some t
88 let unset_global_context_internal () : unit =
89 match !global_context with
90 | Some _
-> global_context := None
91 | None
-> failwith
"unset_global_context_internal: no global context is set"