diff --git a/src/commands/findRefsCommand.ml b/src/commands/findRefsCommand.ml index 894a560c223..99f4968a284 100644 --- a/src/commands/findRefsCommand.ml +++ b/src/commands/findRefsCommand.ml @@ -74,16 +74,23 @@ let main option_values root json pretty strip_root path args () = ServerProt.cmd_to_channel oc (ServerProt.FIND_REFS (file, line, column)); (* command result will be a position structure with full file path *) - let locs: Loc.t list = Timeout.input_value ic in - (* format output *) - print_endline @@ - if json || pretty - then Hh_json.(json_to_string ~pretty @@ - JSON_Array (List.map (Reason.json_of_loc ~strip_root) locs) - ) - else String.concat "\n" @@ - if option_values.from = "vim" || option_values.from = "emacs" - then List.map (Errors.Vim_emacs_output.string_of_loc ~strip_root) locs - else List.map (range_string_of_loc ~strip_root) locs + let response: ServerProt.find_refs_response = Timeout.input_value ic in + match response with + | Ok locs -> + (* format output *) + print_endline @@ + if json || pretty + then Hh_json.(json_to_string ~pretty @@ + JSON_Array (List.map (Reason.json_of_loc ~strip_root) locs) + ) + else String.concat "\n" @@ + if option_values.from = "vim" || option_values.from = "emacs" + then List.map (Errors.Vim_emacs_output.string_of_loc ~strip_root) locs + else List.map (range_string_of_loc ~strip_root) locs + | Error exn_msg -> + Utils_js.prerr_endlinef + "Could not find refs for %s:%d:%d\n%s" + (ServerProt.file_input_get_filename file) line column exn_msg + let command = CommandSpec.command spec main diff --git a/src/server/server.ml b/src/server/server.ml index 0b47563d426..88de6102c78 100644 --- a/src/server/server.ml +++ b/src/server/server.ml @@ -382,13 +382,9 @@ let collate_errors = | _, Some cx, _, _ -> cx | _ -> failwith "Couldn't parse file" in - Some (FindRefs_js.result cx state) + Ok (FindRefs_js.result cx state) with exn -> - Hh_logger.warn - "Could not find refs for %s:%d:%d\n%s" - filename line col - (Printexc.to_string exn); - None + Error (Printexc.to_string exn) in FindRefs_js.unset_hooks (); result @@ -591,10 +587,6 @@ let collate_errors = Marshal.to_channel oc msg []; flush oc in - let marshal_option = function - | Some msg -> marshal msg - | None -> () - in let options = genv.ServerEnv.options in let { ServerProt.client_logging_context; command; } = msg in begin match command with @@ -619,8 +611,8 @@ let collate_errors = (find_module ~options (moduleref, filename): filename option) |> marshal | ServerProt.FIND_REFS (fn, line, char) -> - (find_refs ~options (fn, line, char): Loc.t list option) - |> marshal_option + (find_refs ~options (fn, line, char): ServerProt.find_refs_response) + |> marshal | ServerProt.FORCE_RECHECK (files) -> Marshal.to_channel oc () []; flush oc; diff --git a/src/server/serverProt.ml b/src/server/serverProt.ml index 01bb0aa63f7..ebf2e1d4645 100644 --- a/src/server/serverProt.ml +++ b/src/server/serverProt.ml @@ -75,6 +75,7 @@ type dump_types_response = ( (Loc.t * string * string * string option * Reason.t list) list, Loc.t * string ) result +type find_refs_response = (Loc.t list, string) result type get_def_response = (Loc.t, string) result type infer_type_response = ( Loc.t * string option * string option * Reason.t list,