Skip to content

Commit

Permalink
[flow][cleanup] Rename get_ast to get_ast_from_shared_mem
Browse files Browse the repository at this point in the history
Summary:
Followup of D55548905 to clarify intent.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D55603536

fbshipit-source-id: c83689782981b776dfe95fc103fd558ba4d3b56a
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Apr 2, 2024
1 parent 85b87b3 commit e0eb545
Show file tree
Hide file tree
Showing 26 changed files with 220 additions and 125 deletions.
4 changes: 2 additions & 2 deletions src/codemods/utils/codemod_annotator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ module Make (Extra : BASE_STATS) = struct
Hardcoded_Ty_Fixes.run
~cx
~loc_of_aloc:(Parsing_heaps.Reader_dispatcher.loc_of_aloc ~reader)
~get_ast:(Parsing_heaps.Reader_dispatcher.get_ast ~reader)
~get_ast_from_shared_mem:(Parsing_heaps.Reader_dispatcher.get_ast ~reader)
~file_sig
~typed_ast
~lint_severities
Expand Down Expand Up @@ -218,7 +218,7 @@ module Make (Extra : BASE_STATS) = struct
Hardcoded_Ty_Fixes.run
~cx
~loc_of_aloc:(Parsing_heaps.Reader_dispatcher.loc_of_aloc ~reader)
~get_ast:(Parsing_heaps.Reader_dispatcher.get_ast ~reader)
~get_ast_from_shared_mem:(Parsing_heaps.Reader_dispatcher.get_ast ~reader)
~file_sig
~typed_ast
~lint_severities
Expand Down
2 changes: 1 addition & 1 deletion src/flow_dot_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ let autocomplete filename content line col js_config_object :
~layout_options:Js_layout_generator.default_opts
~haste_module_system:false
~loc_of_aloc
~get_ast:(fun _ -> None)
~get_ast_from_shared_mem:(fun _ -> None)
~get_haste_name:(fun _ -> None)
~get_package_info:(fun _ -> None)
~is_package_file:(fun _ -> false)
Expand Down
46 changes: 30 additions & 16 deletions src/server/command_handler/commandHandler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ let autocomplete
~layout_options:(Code_action_utils.layout_options options)
~haste_module_system:Options.(module_system options = Haste)
~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader)
~get_ast:(Parsing_heaps.Reader.get_ast ~reader)
~get_ast_from_shared_mem:(Parsing_heaps.Reader.get_ast ~reader)
~get_haste_name:(get_haste_name ~reader)
~get_package_info:(Parsing_heaps.Reader.get_package_info ~reader)
~is_package_file:(is_package_file ~reader)
Expand Down Expand Up @@ -707,7 +707,7 @@ let infer_type
| Ok [getdef_loc] ->
Find_documentation.jsdoc_of_getdef_loc
~ast
~get_ast:(Parsing_heaps.Reader.get_ast ~reader)
~get_ast_from_shared_mem:(Parsing_heaps.Reader.get_ast ~reader)
getdef_loc
|> Base.Option.bind ~f:Find_documentation.documentation_of_jsdoc
| _ -> None
Expand Down Expand Up @@ -748,7 +748,7 @@ let insert_type
~env
~profiling
~loc_of_aloc
~get_ast
~get_ast_from_shared_mem
~get_haste_name
~get_type_sig
~file_input
Expand All @@ -765,7 +765,7 @@ let insert_type
~env
~profiling
~loc_of_aloc
~get_ast
~get_ast_from_shared_mem
~get_haste_name
~get_type_sig
~file_key
Expand All @@ -776,30 +776,44 @@ let insert_type
~ambiguity_strategy

let autofix_exports
~options ~env ~profiling ~loc_of_aloc ~get_ast ~get_haste_name ~get_type_sig ~input =
~options
~env
~profiling
~loc_of_aloc
~get_ast_from_shared_mem
~get_haste_name
~get_type_sig
~input =
let file_key = file_key_of_file_input ~options ~env input in
File_input.content_of_file_input input >>= fun file_content ->
Code_action_service.autofix_exports
~options
~master_cx:env.ServerEnv.master_cx
~profiling
~loc_of_aloc
~get_ast
~get_ast_from_shared_mem
~get_haste_name
~get_type_sig
~file_key
~file_content

let autofix_missing_local_annot
~options ~env ~profiling ~loc_of_aloc ~get_ast ~get_haste_name ~get_type_sig ~input =
~options
~env
~profiling
~loc_of_aloc
~get_ast_from_shared_mem
~get_haste_name
~get_type_sig
~input =
let file_key = file_key_of_file_input ~options ~env input in
File_input.content_of_file_input input >>= fun file_content ->
Code_action_service.autofix_missing_local_annot
~options
~master_cx:env.ServerEnv.master_cx
~profiling
~loc_of_aloc
~get_ast
~get_ast_from_shared_mem
~get_haste_name
~get_type_sig
~file_key
Expand Down Expand Up @@ -1179,7 +1193,7 @@ let handle_autocomplete

let handle_autofix_exports ~options ~input ~profiling ~env ~reader =
let loc_of_aloc = Parsing_heaps.Reader.loc_of_aloc ~reader in
let get_ast = Parsing_heaps.Reader.get_ast ~reader in
let get_ast_from_shared_mem = Parsing_heaps.Reader.get_ast ~reader in
let get_haste_name = get_haste_name ~reader in
let get_type_sig = Parsing_heaps.Reader.get_type_sig ~reader in
let result =
Expand All @@ -1190,7 +1204,7 @@ let handle_autofix_exports ~options ~input ~profiling ~env ~reader =
~profiling
~input
~loc_of_aloc
~get_ast
~get_ast_from_shared_mem
~get_haste_name
~get_type_sig
)
Expand All @@ -1199,7 +1213,7 @@ let handle_autofix_exports ~options ~input ~profiling ~env ~reader =

let handle_autofix_missing_local_annot ~options ~input ~profiling ~env ~reader =
let loc_of_aloc = Parsing_heaps.Reader.loc_of_aloc ~reader in
let get_ast = Parsing_heaps.Reader.get_ast ~reader in
let get_ast_from_shared_mem = Parsing_heaps.Reader.get_ast ~reader in
let get_haste_name = get_haste_name ~reader in
let get_type_sig = Parsing_heaps.Reader.get_type_sig ~reader in
let result =
Expand All @@ -1210,7 +1224,7 @@ let handle_autofix_missing_local_annot ~options ~input ~profiling ~env ~reader =
~profiling
~input
~loc_of_aloc
~get_ast
~get_ast_from_shared_mem
~get_haste_name
~get_type_sig
)
Expand Down Expand Up @@ -1303,7 +1317,7 @@ let handle_insert_type
~env
~reader =
let loc_of_aloc = Parsing_heaps.Reader.loc_of_aloc ~reader in
let get_ast = Parsing_heaps.Reader.get_ast ~reader in
let get_ast_from_shared_mem = Parsing_heaps.Reader.get_ast ~reader in
let get_haste_name = get_haste_name ~reader in
let get_type_sig = Parsing_heaps.Reader.get_type_sig ~reader in
let result =
Expand All @@ -1313,7 +1327,7 @@ let handle_insert_type
~env
~profiling
~loc_of_aloc
~get_ast
~get_ast_from_shared_mem
~get_haste_name
~get_type_sig
~file_input
Expand Down Expand Up @@ -1407,7 +1421,7 @@ let find_code_actions ~reader ~options ~env ~profiling ~params ~client =
~imports_ranked_usage
~env
~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader)
~get_ast:(Parsing_heaps.Reader.get_ast ~reader)
~get_ast_from_shared_mem:(Parsing_heaps.Reader.get_ast ~reader)
~get_haste_name:(get_haste_name ~reader)
~get_type_sig:(Parsing_heaps.Reader.get_type_sig ~reader)
~get_package_info:(Parsing_heaps.Reader.get_package_info ~reader)
Expand Down Expand Up @@ -2420,7 +2434,7 @@ let handle_persistent_signaturehelp_lsp
let cursor_loc = Loc.cursor (Some path) line col in
Signature_help.find_signatures
~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader)
~get_ast:(Parsing_heaps.Reader.get_ast ~reader)
~get_ast_from_shared_mem:(Parsing_heaps.Reader.get_ast ~reader)
~cx
~file_sig
~ast
Expand Down
39 changes: 24 additions & 15 deletions src/services/autocomplete/autocompleteService_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ type typing = {
layout_options: Js_layout_generator.opts;
haste_module_system: bool;
loc_of_aloc: ALoc.t -> Loc.t;
get_ast: File_key.t -> (Loc.t, Loc.t) Flow_ast.Program.t option;
get_ast_from_shared_mem: File_key.t -> (Loc.t, Loc.t) Flow_ast.Program.t option;
get_haste_name: File_key.t -> string option;
get_package_info: File_key.t -> (Package_json.t, unit) result option;
is_package_file: string -> bool;
Expand All @@ -329,7 +329,7 @@ let mk_typing_artifacts
~layout_options
~haste_module_system
~loc_of_aloc
~get_ast
~get_ast_from_shared_mem
~get_haste_name
~get_package_info
~is_package_file
Expand All @@ -351,7 +351,7 @@ let mk_typing_artifacts
layout_options;
haste_module_system;
loc_of_aloc;
get_ast;
get_ast_from_shared_mem;
get_haste_name;
get_package_info;
is_package_file;
Expand All @@ -376,15 +376,15 @@ type 'r autocomplete_service_result_generic =

type autocomplete_service_result = AcCompletion.t autocomplete_service_result_generic

let jsdoc_of_def_loc { loc_of_aloc; get_ast; ast; _ } def_loc =
loc_of_aloc def_loc |> Find_documentation.jsdoc_of_getdef_loc ~ast ~get_ast
let jsdoc_of_def_loc { loc_of_aloc; get_ast_from_shared_mem; ast; _ } def_loc =
loc_of_aloc def_loc |> Find_documentation.jsdoc_of_getdef_loc ~ast ~get_ast_from_shared_mem

let jsdoc_of_member typing info =
match info.Ty_members.def_locs with
| [def_loc] -> jsdoc_of_def_loc typing def_loc
| _ -> None

let jsdoc_of_loc ~cx ~loc_of_aloc ~get_ast ~file_sig ~ast ~available_ast loc =
let jsdoc_of_loc ~cx ~loc_of_aloc ~get_ast_from_shared_mem ~file_sig ~ast ~available_ast loc =
let open GetDef_js.Get_def_result in
match
GetDef_js.get_def
Expand All @@ -400,7 +400,7 @@ let jsdoc_of_loc ~cx ~loc_of_aloc ~get_ast ~file_sig ~ast ~available_ast loc =
| Partial (locs, _, _)
when LocSet.cardinal locs = 1 ->
let getdef_loc = LocSet.choose locs in
Find_documentation.jsdoc_of_getdef_loc ~ast ~get_ast getdef_loc
Find_documentation.jsdoc_of_getdef_loc ~ast ~get_ast_from_shared_mem getdef_loc
| _ -> None

let documentation_and_tags_of_jsdoc jsdoc =
Expand All @@ -416,9 +416,10 @@ 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 ~cx ~loc_of_aloc ~get_ast ~file_sig ~ast ~available_ast loc =
let documentation_and_tags_of_loc
~cx ~loc_of_aloc ~get_ast_from_shared_mem ~file_sig ~ast ~available_ast loc =
lazy
(jsdoc_of_loc ~get_ast ~cx ~loc_of_aloc ~file_sig ~ast ~available_ast loc
(jsdoc_of_loc ~get_ast_from_shared_mem ~cx ~loc_of_aloc ~file_sig ~ast ~available_ast loc
|> Base.Option.value_map ~default:(None, None) ~f:documentation_and_tags_of_jsdoc
)

Expand Down Expand Up @@ -481,7 +482,7 @@ let members_of_type
)

let local_value_identifiers ~typing ~genv ~ac_loc =
let { loc_of_aloc; get_ast; cx; ast; available_ast; file_sig; _ } = typing in
let { loc_of_aloc; get_ast_from_shared_mem; 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 @@ -526,7 +527,14 @@ 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 ~get_ast ~cx ~loc_of_aloc ~file_sig ~ast ~available_ast loc
documentation_and_tags_of_loc
~get_ast_from_shared_mem
~cx
~loc_of_aloc
~file_sig
~ast
~available_ast
loc
in
((name, documentation_and_tags), type_)
)
Expand Down Expand Up @@ -1305,7 +1313,7 @@ let autocomplete_unqualified_type
~token =
let {
loc_of_aloc;
get_ast;
get_ast_from_shared_mem;
search_exported_types;
cx;
file_sig;
Expand All @@ -1331,7 +1339,7 @@ let autocomplete_unqualified_type
(fun (items_rev, errors_to_log) ((name, aloc), ty_result) ->
let documentation_and_tags =
documentation_and_tags_of_loc
~get_ast
~get_ast_from_shared_mem
~loc_of_aloc
~cx
~file_sig
Expand Down Expand Up @@ -1899,7 +1907,7 @@ let autocomplete_module_exports ~typing ~edit_locs ~token ~kind ?filter_name mod
AcResult { result = { AcCompletion.items; is_incomplete = false }; errors_to_log }

let unused_super_methods ~typing ~edit_locs ~exclude_keys enclosing_class_t =
let { layout_options; loc_of_aloc; get_ast; _ } = typing in
let { layout_options; loc_of_aloc; get_ast_from_shared_mem; _ } = typing in
let open Base.Result.Let_syntax in
let%bind (mems, errors_to_log) =
members_of_type
Expand All @@ -1916,7 +1924,8 @@ let unused_super_methods ~typing ~edit_locs ~exclude_keys enclosing_class_t =
~f:(fun (name, documentation_and_tags, { Ty_members.ty; def_locs; _ }) ->
let open Base.Option in
(* Find the AST node for member we want to override *)
def_locs |> Base.List.hd >>| loc_of_aloc >>= Find_method.find ~get_ast >>| fun method_ ->
def_locs |> Base.List.hd >>| loc_of_aloc >>= Find_method.find ~get_ast_from_shared_mem
>>| fun method_ ->
autocomplete_create_result_method
~method_
~layout_options
Expand Down
2 changes: 1 addition & 1 deletion src/services/autocomplete/autocompleteService_js.mli
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ val mk_typing_artifacts :
layout_options:Js_layout_generator.opts ->
haste_module_system:bool ->
loc_of_aloc:(ALoc.t -> Loc.t) ->
get_ast:(File_key.t -> (Loc.t, Loc.t) Flow_ast.Program.t option) ->
get_ast_from_shared_mem:(File_key.t -> (Loc.t, Loc.t) Flow_ast.Program.t option) ->
get_haste_name:(File_key.t -> string option) ->
get_package_info:(File_key.t -> (Package_json.t, unit) result option) ->
is_package_file:(string -> bool) ->
Expand Down
4 changes: 2 additions & 2 deletions src/services/autocomplete/find_method.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ let empty_method_of_property_type prop =
)
| _ -> None

let find ~get_ast target_loc =
let find ~get_ast_from_shared_mem target_loc =
let open Base.Option.Let_syntax in
let%bind source = Loc.source target_loc in
let%bind ast = get_ast source in
let%bind ast = get_ast_from_shared_mem source in
try
ignore ((new finder target_loc)#program ast);
None
Expand Down
2 changes: 1 addition & 1 deletion src/services/autocomplete/find_method.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*)

val find :
get_ast:(File_key.t -> (Loc.t, Loc.t) Flow_ast.Program.t option) ->
get_ast_from_shared_mem:(File_key.t -> (Loc.t, Loc.t) Flow_ast.Program.t option) ->
Loc.t ->
(Loc.t, Loc.t) Flow_ast.Class.Method.t Option.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let assert_refactored
~file_sig:(file_sig_of_ast ast)
~typed_ast
~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader)
~get_ast:(Parsing_heaps.Reader.get_ast ~reader)
~get_ast_from_shared_mem:(Parsing_heaps.Reader.get_ast ~reader)
~get_haste_name:(fun f ->
let addr = Parsing_heaps.get_file_addr_unsafe f in
Parsing_heaps.Reader.get_haste_name ~reader addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ let type_synthesizer_tests =
~file_sig
~typed_ast
~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader)
~get_ast:(Parsing_heaps.Reader.get_ast ~reader)
~get_ast_from_shared_mem:(Parsing_heaps.Reader.get_ast ~reader)
~get_haste_name
~get_type_sig:(Parsing_heaps.Reader.get_type_sig ~reader)
~locs
Expand Down
Loading

0 comments on commit e0eb545

Please sign in to comment.