Skip to content

Commit

Permalink
[flow][autocomplete] remove "both" mode of on-demand autocomplete
Browse files Browse the repository at this point in the history
Summary:
This mode makes the code structure a bit awkward since it essentially performs typing twice. Since we only need this for experimentation already under way, we remove it here to make upcoming changes simpler.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D55456833

fbshipit-source-id: 4948c0ac98674d99a970f2a7bcee9661bd837f3b
  • Loading branch information
panagosg7 authored and facebook-github-bot committed Apr 2, 2024
1 parent f702ab9 commit 6abb6e4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 56 deletions.
6 changes: 1 addition & 5 deletions src/commands/config/flowConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,7 @@ module Opts = struct

let autocomplete_mode_parser =
enum
[
("typed_ast", Options.Ac_typed_ast);
("on_demand", Options.Ac_on_demand_typing);
("both", Options.Ac_both);
]
[("typed_ast", Options.Ac_typed_ast); ("on_demand", Options.Ac_on_demand_typing)]
(fun opts v -> Ok { opts with autocomplete_mode = Some v })

let casting_syntax_parser =
Expand Down
1 change: 0 additions & 1 deletion src/common/options.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type react_rules =
type autocomplete_mode =
| Ac_typed_ast
| Ac_on_demand_typing
| Ac_both (* for comparison purposes *)

type format = {
opt_bracket_spacing: bool;
Expand Down
91 changes: 41 additions & 50 deletions src/server/command_handler/commandHandler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,39 @@ let autocomplete
(Error err_str, Some json_data_to_log)
| (Some (Parse_artifacts { docblock = info; file_sig; ast; parse_errors; requires; _ }), _errs)
->
let open AutocompleteService_js in
let ac_options =
{
AutocompleteService_js.imports;
imports_min_characters;
imports_ranked_usage;
imports_ranked_usage_boost_exact_match_min_length;
show_ranking_info;
}
let (cx, available_ast) =
match Options.autocomplete_mode options with
| Options.Ac_typed_ast ->
let (cx, typed_ast) =
Type_contents.check_contents
~options
~profiling
~reader:(State_reader.create ())
env.master_cx
filename
info
ast
requires
file_sig
in
(cx, Typed_ast_utils.Typed_ast typed_ast)
| Options.Ac_on_demand_typing ->
let (cx, aloc_ast) =
Type_contents.compute_env_of_contents
~options
~profiling
~reader:(State_reader.create ())
env.master_cx
filename
info
ast
requires
file_sig
in
(cx, Typed_ast_utils.ALoc_ast aloc_ast)
in
let autocomplete_get_results cx available_ast =
let open AutocompleteService_js in
let (token_opt, ac_loc, ac_type_string, results_res) =
Profiling_js.with_timer profiling ~timer:"GetResults" ~f:(fun () ->
let typing =
AutocompleteService_js.mk_typing_artifacts
Expand All @@ -378,49 +400,18 @@ let autocomplete
~ast
~available_ast
in
let ac_options =
{
AutocompleteService_js.imports;
imports_min_characters;
imports_ranked_usage;
imports_ranked_usage_boost_exact_match_min_length;
show_ranking_info;
}
in
autocomplete_get_results typing ac_options trigger_character cursor_loc
)
in
let autocomplete_fully_type_and_get_results () =
let (cx, typed_ast) =
Type_contents.check_contents
~options
~profiling
~reader:(State_reader.create ())
env.master_cx
filename
info
ast
requires
file_sig
in
autocomplete_get_results cx (Typed_ast_utils.Typed_ast typed_ast)
in
let autocomplete_on_demand_get_results () =
let (cx, aloc_ast) =
Type_contents.compute_env_of_contents
~options
~profiling
~reader:(State_reader.create ())
env.master_cx
filename
info
ast
requires
file_sig
in
autocomplete_get_results cx (Typed_ast_utils.ALoc_ast aloc_ast)
in
let ((token_opt, ac_loc, ac_type_string, results_res), initial_json_props) =
match Options.autocomplete_mode options with
| Options.Ac_typed_ast -> (autocomplete_fully_type_and_get_results (), initial_json_props)
| Options.Ac_on_demand_typing -> (autocomplete_on_demand_get_results (), initial_json_props)
| Options.Ac_both ->
let (_, _, _, r1) = autocomplete_on_demand_get_results () in
let ((_, _, _, r2) as result) = autocomplete_fully_type_and_get_results () in
let equal = AutocompleteService_js.equal_autocomplete_service_result r1 r2 in
(result, ("on_demand_compliance", Hh_json.JSON_Bool equal) :: initial_json_props)
in
(* Make sure hooks are unset *after* we've gotten the results to account for
* on-demand type checking. *)
Autocomplete_js.autocomplete_unset_hooks ();
Expand Down

0 comments on commit 6abb6e4

Please sign in to comment.