Add type annotations to `clientConnect.ml`
[hiphop-php.git] / hphp / hack / src / server / serverCommandTypes.ml
blobbd8dc3ee4bd2fc695ac7af7da8e78f0a3bcc4dcc
1 open Ide_api_types
3 type connection_type =
4 | Persistent
5 | Non_persistent
7 type connection_response =
8 | Connected
10 type status_liveness =
11 | Stale_status
12 | Live_status
14 module Server_status = struct
15 type t = {
16 liveness : status_liveness;
17 has_unsaved_changes : bool;
18 error_list : Pos.absolute Errors.error_ list;
20 end
22 module Identify_symbol = struct
23 type single_result = (string SymbolOccurrence.t) * (string SymbolDefinition.t option)
24 type result = single_result list
25 end
27 module Method_jumps = struct
28 type result = {
29 orig_name: string;
30 orig_pos: Pos.absolute;
31 dest_name: string;
32 dest_pos: Pos.absolute;
33 orig_p_name: string; (* Used for methods to find their parent class *)
34 dest_p_name: string;
37 type filter =
38 | No_filter
39 | Class
40 | Interface
41 | Trait
42 end
44 module Done_or_retry = struct
45 (* This is an ugly hack to support following case:
46 * - client issues a command that requires full recheck. Server knows not to
47 * accept it until full check is completed .
48 * - while processing the command, it turns out that we need to recheck even
49 * more files for full check to be "good enough" for this command
50 * This can happen when combining prechecked files and find references.
51 * We could store the client with its command somwhere, and come back to it
52 * after this additional rechecking is done, but in practice this is ugly to
53 * implement in current atchitecture. What is easier to do instead, is to
54 * return a special "Retry" response to the client, which will cause it to
55 * re-issue the same request (which will once again not be accepted until full
56 * check is completed. Since command is the same, its second execution should
57 * not add even more files to recheck, hence a limit of only two attempts.
59 * In other words: the goal of this is to avoid implementing even more
60 * server-side client queing mechanisms, but re-use an existing "clients waiting
61 * for full check" queue. *)
62 exception Two_retries_in_a_row
64 type 'a t =
65 | Done of 'a
66 | Retry
68 (* Note: this is designed to work with calls that always will succeed on second try
69 * (the reason for retrying is a one time event that is resolved during first call).
70 * If this ends up throwing, it's a bug in hh_server. *)
71 let rec call ~(f:unit -> 'a t) ~(depth:int) : 'a =
72 if depth = 2 then raise Two_retries_in_a_row;
73 match f () with
74 | Done x -> x
75 | Retry -> call ~f ~depth:(depth+1)
77 (* Call the function returning Done_or_retry.t with at most one retry, expecting
78 * that this is enough to yield a non-Retry value, which is returned *)
79 let call ~(f:unit -> 'a t) : 'a = call ~f ~depth:0
81 (* Helper function useful when mapping over results from functions that (in addition
82 * to Done_or_retry.t result) thread through some kind of environment. *)
83 let map_env
84 ~(f:'a -> 'b)
85 ((env, x) : 'env * 'a t)
86 : 'env * 'b t =
87 match x with
88 | Done x -> env, Done (f x)
89 | Retry -> env, Retry
90 end
92 module Find_refs = struct
93 type member =
94 | Method of string
95 | Property of string
96 | Class_const of string
97 | Typeconst of string
99 type action =
100 | Class of string
101 | Member of string * member
102 | Function of string
103 | GConst of string
104 | LocalVar of { filename: Relative_path.t; file_content: string; line: int; char: int }
106 type server_result = (string * Pos.t) list
107 type result = (string * Pos.absolute) list
108 type ide_result = (string * Pos.absolute list) option
110 type server_result_or_retry = server_result Done_or_retry.t
111 type result_or_retry = result Done_or_retry.t
112 type ide_result_or_retry = ide_result Done_or_retry.t
115 module Refactor = struct
116 type ide_result = ((ServerRefactorTypes.patch list), string) result
117 type result = ServerRefactorTypes.patch list
119 type ide_result_or_retry = ide_result Done_or_retry.t
120 type result_or_retry = result Done_or_retry.t
123 module Symbol_type = struct
124 type t = {
125 pos: string Pos.pos;
126 type_: string;
127 ident_: int;
131 module Symbol_info_service = struct
132 type target_type =
133 | Function
134 | Method
135 | Constructor
137 type symbol_fun_call = {
138 name: string;
139 type_: target_type;
140 pos: string Pos.pos;
141 caller: string;
144 type result = {
145 fun_calls: symbol_fun_call list;
146 symbol_types: Symbol_type.t list;
150 module Outline = struct
151 type outline = string SymbolDefinition.t list
154 module Infer_return_type = struct
155 type t =
156 | Function of string
157 | Method of string * string
159 type result = (string, string) Pervasives.result
162 module Ide_refactor_type = struct
163 type t = {
164 filename: string;
165 line: int;
166 char: int;
167 new_name: string;
171 type file_input =
172 | FileName of string
173 | FileContent of string
175 type labelled_file =
176 | LabelledFileName of string
177 | LabelledFileContent of { filename: string; content: string }
179 type lint_stdin_input = { filename: string; contents: string }
181 type cst_search_input = {
182 sort_results: bool;
183 input: Hh_json.json;
184 files_to_search: string list option; (* if None, search all files *)
187 (* The following datatypes can be interpreted as follows:
188 * MESSAGE_TAG : Argument type (sent from client to server) -> return type t *)
189 type _ t =
190 | STATUS : bool -> Server_status.t t
191 | STATUS_SINGLE : file_input -> Pos.absolute Errors.error_ list t
192 | INFER_TYPE : file_input * int * int * bool ->
193 InferAtPosService.result t
194 | INFER_TYPE_BATCH : (string * int * int * (int * int) option) list * bool -> string list t
195 | TYPED_AST : string -> string t
196 | IDE_HOVER : file_input * int * int ->
197 HoverService.result t
198 | DOCBLOCK_AT : (string * int * int * string option) -> DocblockService.result t
199 | IDE_SIGNATURE_HELP : (file_input * int * int) -> Lsp.SignatureHelp.result t
200 | COVERAGE_LEVELS : file_input -> Coverage_level.result t
201 | AUTOCOMPLETE : string -> AutocompleteTypes.result t
202 | IDENTIFY_FUNCTION : file_input * int * int ->
203 Identify_symbol.result t
204 | METHOD_JUMP : (string * Method_jumps.filter * bool) ->
205 Method_jumps.result list t
206 | METHOD_JUMP_BATCH : (string list * Method_jumps.filter) ->
207 Method_jumps.result list t
208 | FIND_REFS : Find_refs.action -> Find_refs.result_or_retry t
209 | IDE_FIND_REFS : labelled_file * int * int * bool ->
210 Find_refs.ide_result_or_retry t
211 | IDE_HIGHLIGHT_REFS : file_input * int * int ->
212 ServerHighlightRefsTypes.result t
213 | REFACTOR : ServerRefactorTypes.action -> Refactor.result_or_retry t
214 | IDE_REFACTOR : Ide_refactor_type.t -> Refactor.ide_result_or_retry t
215 | DUMP_SYMBOL_INFO : string list -> Symbol_info_service.result t
216 | REMOVE_DEAD_FIXMES : int list -> [`Ok of ServerRefactorTypes.patch list | `Error of string] t
217 | IN_MEMORY_DEP_TABLE_SIZE : ((int, string) Pervasives.result) t
218 | SAVE_STATE : (string * bool * bool) -> ((int, string) Pervasives.result) t
219 | SEARCH : string * string -> HackSearchService.result t
220 | COVERAGE_COUNTS : string -> ServerCoverageMetricTypes.result t
221 | LINT : string list -> ServerLintTypes.result t
222 | LINT_STDIN : lint_stdin_input -> ServerLintTypes.result t
223 | LINT_ALL : int -> ServerLintTypes.result t
224 | CREATE_CHECKPOINT : string -> unit t
225 | RETRIEVE_CHECKPOINT : string -> string list option t
226 | DELETE_CHECKPOINT : string -> bool t
227 | STATS : Stats.t t
228 | FORMAT : ServerFormatTypes.action -> ServerFormatTypes.result t
229 | AI_QUERY : string -> string t
230 | DUMP_FULL_FIDELITY_PARSE : string -> string t
231 | OPEN_FILE : string * string -> unit t
232 | CLOSE_FILE : string -> unit t
233 | EDIT_FILE : string * (text_edit list) -> unit t
234 | IDE_AUTOCOMPLETE : string * position * bool * bool -> AutocompleteTypes.ide_result t
235 | IDE_FFP_AUTOCOMPLETE : string * position -> AutocompleteTypes.ide_result t
236 | DISCONNECT : unit t
237 | SUBSCRIBE_DIAGNOSTIC : int -> unit t
238 | UNSUBSCRIBE_DIAGNOSTIC : int -> unit t
239 | OUTLINE : string -> Outline.outline t
240 | IDE_IDLE : unit t
241 | INFER_RETURN_TYPE : Infer_return_type.t ->
242 Infer_return_type.result t
243 | RAGE : ServerRageTypes.result t
244 | DYNAMIC_VIEW: bool -> unit t
245 | CST_SEARCH: cst_search_input -> (Hh_json.json, string) result t
246 | NO_PRECHECKED_FILES: unit t
247 | GEN_HOT_CLASSES: int -> string t
248 | FUN_DEPS_BATCH : (string * int * int) list * bool -> string list t
251 let is_disconnect_rpc : type a. a t -> bool = function
252 | DISCONNECT -> true
253 | _ -> false
256 let is_critical_rpc : type a. a t -> bool = function
257 (* An exception during any critical rpc should shutdown the persistent connection. *)
258 (* The critical ones are those that affect the state. *)
259 | DISCONNECT -> true
260 | CREATE_CHECKPOINT _ -> true
261 | DELETE_CHECKPOINT _ -> true
262 | OPEN_FILE _ -> true
263 | CLOSE_FILE _ -> true
264 | EDIT_FILE _ -> true
265 | SUBSCRIBE_DIAGNOSTIC _ -> true
266 | UNSUBSCRIBE_DIAGNOSTIC _ -> true
267 | _ -> false
269 type 'a command =
270 | Rpc of 'a t
271 | Stream of streamed
272 | Debug
274 and streamed =
275 | SHOW of string
276 | LIST_FILES
277 | LIST_MODES
278 | BUILD of ServerBuild.build_opts
280 type push =
281 | DIAGNOSTIC of int * (Pos.absolute Errors.error_ list) SMap.t
282 | BUSY_STATUS of busy_status
283 | NEW_CLIENT_CONNECTED
284 | FATAL_EXCEPTION of Marshal_tools.remote_exception_data
285 | NONFATAL_EXCEPTION of Marshal_tools.remote_exception_data
287 and busy_status =
288 | Needs_local_typecheck
289 | Doing_local_typecheck
290 | Done_local_typecheck
291 | Doing_global_typecheck of bool (* interruptible? *)
292 | Done_global_typecheck of {is_truncated: bool; shown: int; total: int;}
294 type 'a message_type =
295 | Push of push (* Only sent to persistent connections. *)
296 | Response of 'a * float (* records the time at which hh_server started handling *)
297 | Hello
298 (* Hello is the first message sent after handoff. It's used for both *)
299 (* persistent and non-persistent connections. *)
300 | Ping
301 (* Pings can be sent to non-persistent connection after Hello and before
302 * sending RPC response. *)
304 (** Timeout on reading the command from the client - client probably frozen. *)
305 exception Read_command_timeout