Skip to content

Commit

Permalink
[flow][EZ] Get def and a lot of other IDE services don't need options
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Mar 28, 2024
1 parent 15c67c4 commit 009b910
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 49 deletions.
20 changes: 5 additions & 15 deletions src/server/command_handler/commandHandler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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; _ },
Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions src/services/autocomplete/autocompleteService_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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_)
)
Expand Down Expand Up @@ -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 =
Expand All @@ -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 ->
Expand Down
4 changes: 1 addition & 3 deletions src/services/get_def/getDefUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/services/get_def/getDefUtils.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
9 changes: 4 additions & 5 deletions src/services/get_def/getDef_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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_) } ->
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/services/get_def/getDef_js.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
1 change: 0 additions & 1 deletion src/services/inference/check_service.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
11 changes: 4 additions & 7 deletions src/services/references/findRefs_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)
Expand Down Expand Up @@ -68,16 +68,14 @@ 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
| Types_js_types.Parse_artifacts { ast; file_sig; docblock; _ } -> (ast, file_sig, docblock)
in
let%bind def_info =
GetDefUtils.get_def_info
~options
~reader
~purpose:Get_def_types.Purpose.FindReferences
ast_info
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/services/references/findRefs_js.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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 ->
Expand Down
3 changes: 1 addition & 2 deletions src/services/references/localImportRefSearcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/services/references/localImportRefSearcher.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
3 changes: 1 addition & 2 deletions src/services/type_info/signature_help.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/services/type_info/signature_help.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down

0 comments on commit 009b910

Please sign in to comment.