From 009b910fd813c8cd9dfb52ef9c57711aa55e7562 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Thu, 28 Mar 2024 15:06:00 -0700 Subject: [PATCH] [flow][EZ] Get def and a lot of other IDE services don't need options Summary: Noticed this when I tried to make get_def work in try-flow, which doesn't construct an option. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D55489132 fbshipit-source-id: 8a5d2e583cf3911176da44627f24dbccdfadfcfc --- src/server/command_handler/commandHandler.ml | 20 +++++-------------- .../autocomplete/autocompleteService_js.ml | 17 ++++++++-------- src/services/get_def/getDefUtils.ml | 4 +--- src/services/get_def/getDefUtils.mli | 1 - src/services/get_def/getDef_js.ml | 9 ++++----- src/services/get_def/getDef_js.mli | 1 - src/services/inference/check_service.ml | 1 - src/services/references/findRefs_js.ml | 11 ++++------ src/services/references/findRefs_js.mli | 2 -- .../references/localImportRefSearcher.ml | 3 +-- .../references/localImportRefSearcher.mli | 1 - src/services/type_info/signature_help.ml | 3 +-- src/services/type_info/signature_help.mli | 1 - 13 files changed, 25 insertions(+), 49 deletions(-) diff --git a/src/server/command_handler/commandHandler.ml b/src/server/command_handler/commandHandler.ml index f78f84e5d47..f79208f8cd9 100644 --- a/src/server/command_handler/commandHandler.ml +++ b/src/server/command_handler/commandHandler.ml @@ -476,7 +476,7 @@ let check_file ~options ~env ~profiling ~force file_input = (* This returns result, json_data_to_log, where json_data_to_log is the json data from * getdef_get_result which we end up using *) -let get_def_of_check_result ~options ~reader ~profiling ~check_result (file, line, col) = +let get_def_of_check_result ~reader ~profiling ~check_result (file, line, col) = Profiling_js.with_timer profiling ~timer:"GetResult" ~f:(fun () -> let loc = Loc.cursor (Some file) line col in let ( Parse_artifacts { ast; file_sig; parse_errors; _ }, @@ -485,7 +485,6 @@ let get_def_of_check_result ~options ~reader ~profiling ~check_result (file, lin check_result in GetDef_js.get_def - ~options ~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader) ~cx ~file_sig @@ -633,12 +632,7 @@ let infer_type in let (getdef_loc_result, _) = try_with_json (fun () -> - get_def_of_check_result - ~options - ~reader - ~profiling - ~check_result - (file_key, line, column) + get_def_of_check_result ~reader ~profiling ~check_result (file_key, line, column) ) in let get_def_documentation = @@ -962,7 +956,7 @@ let get_def ~options ~reader ~env ~profiling ~type_parse_artifacts_cache (file_i (Error msg, Some (Hh_json.JSON_Object json_props)) | Ok check_result -> let (result, json_props) = - get_def_of_check_result ~options ~reader ~profiling ~check_result (file_key, line, col) + get_def_of_check_result ~reader ~profiling ~check_result (file_key, line, col) in let json = let json_props = Base.Option.value ~default:[] json_props in @@ -2264,7 +2258,7 @@ let handle_persistent_signaturehelp_lsp | Ok (Parse_artifacts { ast; file_sig; _ }, Typecheck_artifacts { cx; typed_ast; _ }) -> let func_details = let cursor_loc = Loc.cursor (Some path) line col in - Signature_help.find_signatures ~options ~reader ~cx ~file_sig ~ast ~typed_ast cursor_loc + Signature_help.find_signatures ~reader ~cx ~file_sig ~ast ~typed_ast cursor_loc in (match func_details with | Ok details -> @@ -2319,7 +2313,7 @@ let get_file_artifacts ~options ~client ~profiling ~env pos : (Error err_str, Some (Hh_json.JSON_Object json_props)) | Ok file_artifacts -> (Ok (Some (file_artifacts, file_key)), None)) -let find_local_references ~reader ~options ~file_artifacts ~kind file_key pos : +let find_local_references ~reader ~file_artifacts ~kind file_key pos : ((Get_def_types.def_info * FindRefsTypes.find_refs_ok, string) result * Hh_json.json option) Lwt.t = let (parse_artifacts, typecheck_artifacts) = file_artifacts in @@ -2328,7 +2322,6 @@ let find_local_references ~reader ~options ~file_artifacts ~kind file_key pos : let results = FindRefs_js.find_local_refs ~reader - ~options ~file_key ~parse_artifacts ~typecheck_artifacts @@ -2370,7 +2363,6 @@ let map_local_find_references_results ~reader ~options ~client ~profiling ~env ~ let%lwt (local_refs, extra_data) = find_local_references ~reader - ~options ~file_artifacts ~kind:FindRefsTypes.FindReferences file_key @@ -2429,7 +2421,6 @@ let handle_global_find_references let (line, col) = Flow_lsp_conversions.position_of_document_position text_doc_position in (match FindRefs_js.find_local_refs - ~options ~reader ~file_key ~parse_artifacts @@ -2657,7 +2648,6 @@ let handle_persistent_rename ~reader ~options ~id ~params ~metadata ~client ~pro let%lwt (all_refs, extra_data) = find_local_references ~reader - ~options ~file_artifacts ~kind:FindRefsTypes.Rename file_key diff --git a/src/services/autocomplete/autocompleteService_js.ml b/src/services/autocomplete/autocompleteService_js.ml index a2efa76241f..2f9a275ef61 100644 --- a/src/services/autocomplete/autocompleteService_js.ml +++ b/src/services/autocomplete/autocompleteService_js.ml @@ -398,11 +398,10 @@ let jsdoc_of_member typing info = | [def_loc] -> jsdoc_of_def_loc typing def_loc | _ -> None -let jsdoc_of_loc ~options ~reader ~cx ~file_sig ~ast ~available_ast loc = +let jsdoc_of_loc ~reader ~cx ~file_sig ~ast ~available_ast loc = let open GetDef_js.Get_def_result in match GetDef_js.get_def - ~options ~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader) ~cx ~file_sig @@ -431,9 +430,9 @@ let documentation_and_tags_of_member typing info = |> Base.Option.value_map ~default:(None, None) ~f:documentation_and_tags_of_jsdoc ) -let documentation_and_tags_of_loc ~options ~reader ~cx ~file_sig ~ast ~available_ast loc = +let documentation_and_tags_of_loc ~reader ~cx ~file_sig ~ast ~available_ast loc = lazy - (jsdoc_of_loc ~options ~reader ~cx ~file_sig ~ast ~available_ast loc + (jsdoc_of_loc ~reader ~cx ~file_sig ~ast ~available_ast loc |> Base.Option.value_map ~default:(None, None) ~f:documentation_and_tags_of_jsdoc ) @@ -496,7 +495,7 @@ let members_of_type ) let local_value_identifiers ~typing ~genv ~ac_loc = - let { options; reader; cx; ast; available_ast; file_sig; _ } = typing in + let { reader; cx; ast; available_ast; file_sig; _ } = typing in let scope_info = Scope_builder.program ~enable_enums:(Context.enable_enums cx) ~with_types:false ast in @@ -541,7 +540,7 @@ let local_value_identifiers ~typing ~genv ~ac_loc = Type_env.checked_find_loc_env_write_opt cx Env_api.OrdinaryNameLoc (ALoc.of_loc loc) in let documentation_and_tags = - documentation_and_tags_of_loc ~options ~reader ~cx ~file_sig ~ast ~available_ast loc + documentation_and_tags_of_loc ~reader ~cx ~file_sig ~ast ~available_ast loc in ((name, documentation_and_tags), type_) ) @@ -1302,7 +1301,9 @@ let autocomplete_unqualified_type ~ac_loc ~edit_locs ~token = - let { options; reader; cx; file_sig; ast; available_ast; exports; norm_genv = genv } = typing in + let { options = _; reader; cx; file_sig; ast; available_ast; exports; norm_genv = genv } = + typing + in let ac_loc = loc_of_aloc ~reader ac_loc |> Autocomplete_sigil.remove_from_loc in let exact_by_default = Context.exact_by_default cx in let items_rev = @@ -1318,7 +1319,7 @@ let autocomplete_unqualified_type (fun (items_rev, errors_to_log) ((name, aloc), ty_result) -> let documentation_and_tags = loc_of_aloc ~reader aloc - |> documentation_and_tags_of_loc ~options ~reader ~cx ~file_sig ~ast ~available_ast + |> documentation_and_tags_of_loc ~reader ~cx ~file_sig ~ast ~available_ast in match ty_result with | Ok elt -> diff --git a/src/services/get_def/getDefUtils.ml b/src/services/get_def/getDefUtils.ml index 2954c5df5d5..916b6037b64 100644 --- a/src/services/get_def/getDefUtils.ml +++ b/src/services/get_def/getDefUtils.ml @@ -543,8 +543,7 @@ let get_property_def_info ~loc_of_aloc type_info loc : (property_def_info option ~default:(Ok None) def_kind -let get_def_info ~options ~reader ~purpose (ast, file_sig, _) type_info loc : - (def_info, string) result = +let get_def_info ~reader ~purpose (ast, file_sig, _) type_info loc : (def_info, string) result = let (Types_js_types.Typecheck_artifacts { cx; typed_ast; obj_to_obj_map = _ }) = type_info in let loc_of_aloc = Parsing_heaps.Reader.loc_of_aloc ~reader in match get_property_def_info ~loc_of_aloc type_info loc with @@ -553,7 +552,6 @@ let get_def_info ~options ~reader ~purpose (ast, file_sig, _) type_info loc : | Ok None -> (match GetDef_js.get_def - ~options ~loc_of_aloc ~cx ~file_sig diff --git a/src/services/get_def/getDefUtils.mli b/src/services/get_def/getDefUtils.mli index 6b1148b9337..b12b1526f75 100644 --- a/src/services/get_def/getDefUtils.mli +++ b/src/services/get_def/getDefUtils.mli @@ -31,7 +31,6 @@ val get_property_def_info : (property_def_info option, string) result val get_def_info : - options:Options.t -> reader:Parsing_heaps.Reader.reader -> purpose:Purpose.t -> FindRefsUtils.ast_info -> diff --git a/src/services/get_def/getDef_js.ml b/src/services/get_def/getDef_js.ml index 5d723c874c3..c318e8b9ff4 100644 --- a/src/services/get_def/getDef_js.ml +++ b/src/services/get_def/getDef_js.ml @@ -33,7 +33,7 @@ let extract_member_def ~loc_of_aloc ~cx ~file_sig ~typed_ast_opt ~force_instance | Some def_locs -> Ok (Nel.map loc_of_aloc def_locs, Some name) | None -> Error (Printf.sprintf "failed to find member %s in members map" name) -let rec process_request ~options ~loc_of_aloc ~cx ~is_legit_require ~ast ~typed_ast_opt ~file_sig : +let rec process_request ~loc_of_aloc ~cx ~is_legit_require ~ast ~typed_ast_opt ~file_sig : (ALoc.t, ALoc.t * Type.t) Get_def_request.t -> (Loc.t Nel.t * string option, string) result = function | Get_def_request.Identifier { name; loc = (aloc, type_) } -> @@ -50,7 +50,7 @@ let rec process_request ~options ~loc_of_aloc ~cx ~is_legit_require ~ast ~typed_ Ok (def_loc, Some name) | [] -> let req = Get_def_request.Type { annot = (aloc, type_); name = Some name } in - process_request ~options ~loc_of_aloc ~cx ~is_legit_require ~ast ~typed_ast_opt ~file_sig req + process_request ~loc_of_aloc ~cx ~is_legit_require ~ast ~typed_ast_opt ~file_sig req | _ :: _ :: _ -> Error "Scope builder found multiple matching identifiers") | Get_def_request.(Member { prop_name = name; object_type = (_loc, t); force_instance }) -> extract_member_def ~loc_of_aloc ~cx ~file_sig ~typed_ast_opt ~force_instance t name @@ -70,7 +70,7 @@ let rec process_request ~options ~loc_of_aloc ~cx ~is_legit_require ~ast ~typed_ Member { prop_name = name; object_type = (loc, props_object); force_instance = false } ) in - process_request ~options ~loc_of_aloc ~cx ~is_legit_require ~ast ~typed_ast_opt ~file_sig req + process_request ~loc_of_aloc ~cx ~is_legit_require ~ast ~typed_ast_opt ~file_sig req module Depth = struct let limit = 100 @@ -119,7 +119,7 @@ module Depth = struct depth.results <- Loc_collections.LocMap.add loc result results end -let get_def ~options ~loc_of_aloc ~cx ~file_sig ~ast ~available_ast ~purpose requested_loc = +let get_def ~loc_of_aloc ~cx ~file_sig ~ast ~available_ast ~purpose requested_loc = let require_loc_map = File_sig.require_loc_map file_sig in let is_legit_require source_aloc = let source_loc = loc_of_aloc source_aloc in @@ -153,7 +153,6 @@ let get_def ~options ~loc_of_aloc ~cx ~file_sig ~ast ~available_ast ~purpose req | Request request -> begin match process_request - ~options ~loc_of_aloc ~cx ~is_legit_require diff --git a/src/services/get_def/getDef_js.mli b/src/services/get_def/getDef_js.mli index 4b4ac7ad822..6fe4f556acc 100644 --- a/src/services/get_def/getDef_js.mli +++ b/src/services/get_def/getDef_js.mli @@ -16,7 +16,6 @@ module Get_def_result : sig end val get_def : - options:Options.t -> loc_of_aloc:(ALoc.t -> Loc.t) -> cx:Context.t -> file_sig:File_sig.t -> diff --git a/src/services/inference/check_service.ml b/src/services/inference/check_service.ml index ab92e6db155..69addc2265b 100644 --- a/src/services/inference/check_service.ml +++ b/src/services/inference/check_service.ml @@ -317,7 +317,6 @@ let mk_check_file ~reader ~options ~master_cx ~cache () = in let find_refs_result = FindRefs_js.local_refs_of_find_ref_request - ~options ~loc_of_aloc:(Parsing_heaps.Reader_dispatcher.loc_of_aloc ~reader) (ast, file_sig, docblock) (Types_js_types.Typecheck_artifacts { cx; typed_ast; obj_to_obj_map }) diff --git a/src/services/references/findRefs_js.ml b/src/services/references/findRefs_js.ml index 8002d850a32..2e0faaca8a8 100644 --- a/src/services/references/findRefs_js.ml +++ b/src/services/references/findRefs_js.ml @@ -13,16 +13,16 @@ let sort_and_dedup refs = Base.List.dedup_and_sort ~compare:(fun (_, loc1) (_, loc2) -> Loc.compare loc1 loc2) refs let local_refs_of_find_ref_request - ~options ~loc_of_aloc ast_info type_info file_key { FindRefsTypes.def_info; kind = _ } = + ~loc_of_aloc ast_info type_info file_key { FindRefsTypes.def_info; kind = _ } = let var_refs prop_refs = let def_locs = GetDefUtils.all_locs_of_def_info def_info in let (ast, file_sig, _) = ast_info in let (Types_js_types.Typecheck_artifacts { cx; typed_ast; _ }) = type_info in let { LocalImportRefSearcher.local_locs = import_def_locs; remote_locs } = - LocalImportRefSearcher.search ~options ~loc_of_aloc ~cx ~file_sig ~ast ~typed_ast def_locs + LocalImportRefSearcher.search ~loc_of_aloc ~cx ~file_sig ~ast ~typed_ast def_locs in let scope_info = - Scope_builder.program ~enable_enums:(Options.enums options) ~with_types:true ast + Scope_builder.program ~enable_enums:(Context.enable_enums cx) ~with_types:true ast in (* Property refs might contain binding destructuring pattern identifiers. * We should find all local references of them. *) @@ -68,8 +68,7 @@ let local_refs_of_find_ref_request merge_with_var_refs prop_refs | Get_def_types.NoDefinition no_def_reason -> Ok (FindRefsTypes.NoDefinition no_def_reason) -let find_local_refs - ~reader ~options ~file_key ~parse_artifacts ~typecheck_artifacts ~kind ~line ~col = +let find_local_refs ~reader ~file_key ~parse_artifacts ~typecheck_artifacts ~kind ~line ~col = let open Base.Result.Let_syntax in let ast_info = match parse_artifacts with @@ -77,7 +76,6 @@ let find_local_refs in let%bind def_info = GetDefUtils.get_def_info - ~options ~reader ~purpose:Get_def_types.Purpose.FindReferences ast_info @@ -86,7 +84,6 @@ let find_local_refs in let%bind result = local_refs_of_find_ref_request - ~options ~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader) ast_info typecheck_artifacts diff --git a/src/services/references/findRefs_js.mli b/src/services/references/findRefs_js.mli index b688abce3f3..d12012f57ec 100644 --- a/src/services/references/findRefs_js.mli +++ b/src/services/references/findRefs_js.mli @@ -7,7 +7,6 @@ val find_local_refs : reader:State_reader.t -> - options:Options.t -> file_key:File_key.t -> parse_artifacts:Types_js_types.parse_artifacts -> typecheck_artifacts:Types_js_types.typecheck_artifacts -> @@ -17,7 +16,6 @@ val find_local_refs : (Get_def_types.def_info * FindRefsTypes.find_refs_ok, string) result val local_refs_of_find_ref_request : - options:Options.t -> loc_of_aloc:(ALoc.t -> Loc.t) -> FindRefsUtils.ast_info -> Types_js_types.typecheck_artifacts -> diff --git a/src/services/references/localImportRefSearcher.ml b/src/services/references/localImportRefSearcher.ml index ca6b02ccba3..3b46e95e1f2 100644 --- a/src/services/references/localImportRefSearcher.ml +++ b/src/services/references/localImportRefSearcher.ml @@ -12,7 +12,7 @@ type search_result = { remote_locs: Loc.t list; } -let search ~options ~loc_of_aloc ~cx ~file_sig ~ast ~typed_ast def_locs = +let search ~loc_of_aloc ~cx ~file_sig ~ast ~typed_ast def_locs = let open File_sig in let require_name_locs = Base.List.fold (File_sig.requires file_sig) ~init:[] ~f:(fun acc -> function @@ -54,7 +54,6 @@ let search ~options ~loc_of_aloc ~cx ~file_sig ~ast ~typed_ast def_locs = ~f:(fun ((local_locs, remote_locs) as acc) (remote_loc, local_loc) -> match GetDef_js.get_def - ~options ~loc_of_aloc ~cx ~file_sig diff --git a/src/services/references/localImportRefSearcher.mli b/src/services/references/localImportRefSearcher.mli index a066bc7c664..0f085c83fc3 100644 --- a/src/services/references/localImportRefSearcher.mli +++ b/src/services/references/localImportRefSearcher.mli @@ -11,7 +11,6 @@ type search_result = { } val search : - options:Options.t -> loc_of_aloc:(ALoc.t -> Loc.t) -> cx:Context.t -> file_sig:File_sig.t -> diff --git a/src/services/type_info/signature_help.ml b/src/services/type_info/signature_help.ml index 8b09b3f0765..37addd5fc82 100644 --- a/src/services/type_info/signature_help.ml +++ b/src/services/type_info/signature_help.ml @@ -290,7 +290,7 @@ let rec fix_alias_reason cx t = IntersectionT (r, InterRep.make t0 t1 ts) | _ -> t' -let find_signatures ~options ~reader ~cx ~file_sig ~ast ~typed_ast loc = +let find_signatures ~reader ~cx ~file_sig ~ast ~typed_ast loc = match Callee_finder.find_opt ~reader ~cx ~typed_ast loc with | Some (t, active_parameter, callee_loc) -> let t' = fix_alias_reason cx t in @@ -302,7 +302,6 @@ let find_signatures ~options ~reader ~cx ~file_sig ~ast ~typed_ast loc = let jsdoc = match GetDef_js.get_def - ~options ~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader) ~cx ~file_sig diff --git a/src/services/type_info/signature_help.mli b/src/services/type_info/signature_help.mli index f5ac07a5fe5..4de1b6ed8a0 100644 --- a/src/services/type_info/signature_help.mli +++ b/src/services/type_info/signature_help.mli @@ -14,7 +14,6 @@ val func_details : ServerProt.Response.func_details_result val find_signatures : - options:Options.t -> reader:State_reader.t -> cx:Context.t -> file_sig:File_sig.t ->