diff --git a/src/server/command_handler/commandHandler.ml b/src/server/command_handler/commandHandler.ml index f3d2e9aa7c6..f9aad5b9dd8 100644 --- a/src/server/command_handler/commandHandler.ml +++ b/src/server/command_handler/commandHandler.ml @@ -280,6 +280,21 @@ let get_status ~options env = in (status_response, lazy_stats) +let autoimport_options ~ac_options = + let open Export_search in + { + default_options with + max_results = 100; + num_threads = Base.Int.max 1 (Sys_utils.nbr_procs - 2); + weighted = ac_options.AutocompleteService_js.imports_ranked_usage; + } + +let search_exported_values ~exports ~ac_options before = + Export_search.search_values ~options:(autoimport_options ~ac_options) before exports + +let search_exported_types ~exports ~ac_options before = + Export_search.search_types ~options:(autoimport_options ~ac_options) before exports + let autocomplete ~trigger_character ~reader @@ -354,11 +369,12 @@ let autocomplete ~get_haste_name:(get_haste_name ~reader) ~get_package_info:(Parsing_heaps.Reader.get_package_info ~reader) ~is_package_file:(is_package_file ~reader) + ~search_exported_values:(search_exported_values ~exports:env.ServerEnv.exports) + ~search_exported_types:(search_exported_types ~exports:env.ServerEnv.exports) ~cx ~file_sig ~ast ~available_ast - ~exports:env.ServerEnv.exports in autocomplete_get_results typing ac_options trigger_character cursor_loc ) diff --git a/src/services/autocomplete/autocompleteService_js.ml b/src/services/autocomplete/autocompleteService_js.ml index fe45a7cac3f..e4541135386 100644 --- a/src/services/autocomplete/autocompleteService_js.ml +++ b/src/services/autocomplete/autocompleteService_js.ml @@ -10,16 +10,6 @@ open Loc_collections module Ast = Flow_ast module Statement = Fix_statement.Statement_ -let max_autoimport_suggestions = 100 - -let default_autoimport_options = - let open Export_search in - { - default_options with - max_results = max_autoimport_suggestions; - num_threads = Base.Int.max 1 (Sys_utils.nbr_procs - 2); - } - module AcCompletion = struct type completion_item = { kind: Lsp.Completion.completionItemKind option; @@ -358,11 +348,12 @@ type typing = { 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; + search_exported_values: ac_options:ac_options -> string -> Export_search_types.search_results; + search_exported_types: ac_options:ac_options -> string -> Export_search_types.search_results; cx: Context.t; file_sig: File_sig.t; ast: (Loc.t, Loc.t) Flow_ast.Program.t; available_ast: Typed_ast_utils.available_ast; - exports: Export_search.t; norm_genv: Ty_normalizer_env.genv; } @@ -373,11 +364,12 @@ let mk_typing_artifacts ~get_haste_name ~get_package_info ~is_package_file + ~search_exported_values + ~search_exported_types ~cx ~file_sig ~ast - ~available_ast - ~exports = + ~available_ast = let norm_genv = Ty_normalizer_flow.mk_genv ~options:ty_normalizer_options @@ -392,11 +384,12 @@ let mk_typing_artifacts get_haste_name; get_package_info; is_package_file; + search_exported_values; + search_exported_types; cx; file_sig; ast; available_ast; - exports; norm_genv; } @@ -982,13 +975,7 @@ let autocomplete_id else let locals = set_of_locals ~f:(fun ((name, _docs_and_tags), _ty) -> name) identifiers in let { Export_search_types.results = auto_imports; is_incomplete } = - let options = - { - default_autoimport_options with - Export_search.weighted = ac_options.imports_ranked_usage; - } - in - Export_search.search_values ~options before typing.exports + typing.search_exported_values ~ac_options before in let items_rev = append_completion_items_of_autoimports @@ -1343,11 +1330,12 @@ let autocomplete_unqualified_type get_haste_name = _; get_package_info = _; is_package_file = _; + search_exported_values = _; + search_exported_types; cx; file_sig; ast; available_ast; - exports; norm_genv = genv; } = typing @@ -1464,13 +1452,7 @@ let autocomplete_unqualified_type in let { Export_search_types.results = auto_imports; is_incomplete } = let (before, _after) = Autocomplete_sigil.remove token in - let options = - { - default_autoimport_options with - Export_search.weighted = ac_options.imports_ranked_usage; - } - in - Export_search.search_types ~options before exports + search_exported_types ~ac_options before in let items_rev = append_completion_items_of_autoimports diff --git a/src/services/autocomplete/autocompleteService_js.mli b/src/services/autocomplete/autocompleteService_js.mli index 9b305ae3130..51dd8e1ba35 100644 --- a/src/services/autocomplete/autocompleteService_js.mli +++ b/src/services/autocomplete/autocompleteService_js.mli @@ -28,11 +28,12 @@ val mk_typing_artifacts : 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) -> + search_exported_values:(ac_options:ac_options -> string -> Export_search_types.search_results) -> + search_exported_types:(ac_options:ac_options -> string -> Export_search_types.search_results) -> cx:Context.t -> file_sig:File_sig.t -> ast:(Loc.t, Loc.t) Flow_ast.Program.t -> available_ast:Typed_ast_utils.available_ast -> - exports:Export_search.t -> typing type 'r autocomplete_service_result_generic = diff --git a/src/services/autocomplete/dune b/src/services/autocomplete/dune index 7e0cc2bd89c..0b5b13a4e0a 100644 --- a/src/services/autocomplete/dune +++ b/src/services/autocomplete/dune @@ -3,7 +3,7 @@ (wrapped false) (libraries fuzzy_score - flow_search + flow_search_types flow_server_protocol flow_service_type_info flow_typing