Skip to content

Commit

Permalink
[flow] autocomplete comparison mode
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal]

This diff adds a "comparison" mode enabled with `experimental.autocomplete_mode=both`, that compares the results of on-demand and full-inference autocomplete.

Reviewed By: SamChou19815

Differential Revision: D55231177

fbshipit-source-id: 8bff0da96e672d7504eddd6cc2899638aefda9f2
  • Loading branch information
panagosg7 authored and facebook-github-bot committed Mar 22, 2024
1 parent b2831b1 commit b4617be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/commands/config/flowConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ module Opts = struct

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

let casting_syntax_parser =
Expand Down
1 change: 1 addition & 0 deletions src/common/options.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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
11 changes: 8 additions & 3 deletions src/server/command_handler/commandHandler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,15 @@ let autocomplete
in
autocomplete_get_results cx (Typed_ast_utils.ALoc_ast aloc_ast)
in
let (token_opt, ac_loc, ac_type_string, results_res) =
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 ()
| Options.Ac_on_demand_typing -> autocomplete_on_demand_get_results ()
| 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. *)
Expand Down

0 comments on commit b4617be

Please sign in to comment.