Skip to content

Commit

Permalink
[flow][autocomplete] remove non-canonical mode
Browse files Browse the repository at this point in the history
Reviewed By: SamChou19815

Differential Revision: D57122492

fbshipit-source-id: 137fabfad3ebc538c3d3e3beb8ec8caa46a96e87
  • Loading branch information
panagosg7 authored and facebook-github-bot committed May 8, 2024
1 parent de0a059 commit 60d9126
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 72 deletions.
2 changes: 0 additions & 2 deletions src/commands/commandUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 +1479,6 @@ let make_options
Option.value
options_flags.long_lived_workers
~default:(FlowConfig.long_lived_workers flowconfig);
opt_autocomplete_canonical =
Base.Option.value (FlowConfig.autocomplete_canonical flowconfig) ~default:Options.Ac_canonical;
(* Not user-configurable for now, but set to false for some codemods. *)
opt_any_propagation = true;
}
Expand Down
10 changes: 0 additions & 10 deletions src/commands/config/flowConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ module Opts = struct

type t = {
all: bool option;
autocomplete_canonical: Options.autocomplete_canonical option;
autoimports: bool option;
autoimports_min_characters: int option;
autoimports_ranked_by_usage: bool option;
Expand Down Expand Up @@ -172,7 +171,6 @@ module Opts = struct
let default_options =
{
all = None;
autocomplete_canonical = None;
autoimports = None;
autoimports_min_characters = None;
autoimports_ranked_by_usage = None;
Expand Down Expand Up @@ -387,11 +385,6 @@ module Opts = struct
let max_seconds_for_check_per_worker_parser =
uint (fun opts v -> Ok { opts with max_seconds_for_check_per_worker = float v })

let autocomplete_canonical_parser =
enum
[("canonical", Options.Ac_canonical); ("classic", Options.Ac_classic)]
(fun opts v -> Ok { opts with autocomplete_canonical = Some v })

let casting_syntax_parser =
enum
[
Expand Down Expand Up @@ -857,7 +850,6 @@ module Opts = struct
let parsers =
[
("all", boolean (fun opts v -> Ok { opts with all = Some v }));
("experimental.autocomplete_canonical", autocomplete_canonical_parser);
("autoimports", boolean (fun opts v -> Ok { opts with autoimports = Some v }));
( "autoimports.min_characters",
uint (fun opts v ->
Expand Down Expand Up @@ -1531,8 +1523,6 @@ let libs config = config.libs

let all c = c.options.Opts.all

let autocomplete_canonical c = c.options.Opts.autocomplete_canonical

let autoimports c = c.options.Opts.autoimports

let autoimports_min_characters c = c.options.Opts.autoimports_min_characters
Expand Down
2 changes: 0 additions & 2 deletions src/commands/config/flowConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ val enabled_rollouts : config -> string SMap.t
(* options *)
val all : config -> bool option

val autocomplete_canonical : config -> Options.autocomplete_canonical option

val autoimports : config -> bool option

val autoimports_min_characters : config -> int option
Expand Down
7 changes: 0 additions & 7 deletions src/common/options.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ type react_rules =
| DeepReadOnlyHookReturns
| RulesOfHooks

type autocomplete_canonical =
| Ac_canonical
| Ac_classic

type format = {
opt_bracket_spacing: bool;
opt_single_quotes: bool;
Expand Down Expand Up @@ -71,7 +67,6 @@ type t = {
opt_all: bool;
opt_as_const: bool;
opt_any_propagation: bool;
opt_autocomplete_canonical: autocomplete_canonical;
opt_autoimports: bool;
opt_autoimports_min_characters: int;
opt_autoimports_ranked_by_usage: bool;
Expand Down Expand Up @@ -166,8 +161,6 @@ let as_const opts = opts.opt_as_const

let any_propagation opts = opts.opt_any_propagation

let autocomplete_canonical opts = opts.opt_autocomplete_canonical

let autoimports opts = opts.opt_autoimports

let autoimports_min_characters opts = opts.opt_autoimports_min_characters
Expand Down
4 changes: 1 addition & 3 deletions src/flow_dot_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ let autocomplete filename content line col js_config_object :
let filename = File_key.SourceFile filename in
let root = File_path.dummy_path in
let cursor_loc = Loc.cursor (Some filename) line col in
let (content, _, canon_token) =
Autocomplete_sigil.add_canonical (Some filename) content line col
in
let (content, _, canon_token) = Autocomplete_sigil.add (Some filename) content line col in
let canon_cursor =
Base.Option.value_map ~default:cursor_loc ~f:Autocomplete_sigil.Canonical.cursor canon_token
in
Expand Down
21 changes: 5 additions & 16 deletions src/server/command_handler/commandHandler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ let json_of_autocomplete_result initial_json_props = function
(response, Some (Hh_json.JSON_Object json_props_to_log))

let type_parse_artifacts_for_ac_with_cache
~options ~profiling ~type_parse_artifacts_cache ~cached master_cx file contents artifacts =
~options ~profiling ~type_parse_artifacts_cache master_cx file contents artifacts =
let type_parse_artifacts =
lazy
(match Lazy.force artifacts with
Expand All @@ -412,7 +412,7 @@ let type_parse_artifacts_for_ac_with_cache
| Ok (contents', _, _, _) -> contents = contents'
in
match type_parse_artifacts_cache with
| Some cache when cached ->
| Some cache ->
let (result, did_hit) = FilenameCache.with_cache_sync ~cond file type_parse_artifacts cache in
(result, Some did_hit)
| _ -> (Lazy.force type_parse_artifacts, None)
Expand All @@ -431,8 +431,7 @@ let autocomplete_on_parsed
~imports_min_characters
~imports_ranked_usage
~imports_ranked_usage_boost_exact_match_min_length
~show_ranking_info
~canonical =
~show_ranking_info =
let cursor_loc =
let (line, column) = cursor in
Loc.cursor (Some filename) line column
Expand All @@ -441,11 +440,7 @@ let autocomplete_on_parsed
* We will refer to this form of contents as canonical. *)
let (contents, broader_context, canon_token) =
let (line, column) = cursor in
if canonical then
Autocomplete_sigil.add_canonical (Some filename) contents line column
else
let (contents, broader_context) = Autocomplete_sigil.add contents line column in
(contents, broader_context, None)
Autocomplete_sigil.add (Some filename) contents line column
in
let canon_cursor =
Base.Option.value_map ~default:cursor_loc ~f:Autocomplete_sigil.Canonical.cursor canon_token
Expand All @@ -469,7 +464,6 @@ let autocomplete_on_parsed
~options
~profiling
~type_parse_artifacts_cache
~cached:canonical
env.master_cx
filename
contents
Expand Down Expand Up @@ -546,7 +540,7 @@ let autocomplete
let extra_data = json_of_skipped reason in
(Ok response, extra_data)
| Ok (filename, contents) ->
let autocomplete =
let (initial_json_props, ac_result) =
autocomplete_on_parsed
~filename
~contents
Expand All @@ -563,11 +557,6 @@ let autocomplete
~imports_ranked_usage_boost_exact_match_min_length
~show_ranking_info
in
let (initial_json_props, ac_result) =
match Options.autocomplete_canonical options with
| Options.Ac_classic -> autocomplete ~canonical:false
| Options.Ac_canonical -> autocomplete ~canonical:true
in
json_of_autocomplete_result initial_json_props ac_result

let check_file ~options ~env ~profiling ~force file_input =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ let tests =
( "empty_line" >:: fun ctxt ->
let contents = "// @flow\n\nfoo\n\nbar" in
let expected = "// @flow\n\nfoo\nAUTO332\nbar" in
let (actual, broader_context, _) =
Autocomplete_sigil.add_canonical None contents 4 0
in
let (actual, broader_context, _) = Autocomplete_sigil.add None contents 4 0 in
assert_equal ~ctxt ~printer:(fun x -> x) expected actual;
let expected = "foo\nAUTO332\nbar" in
assert_equal ~ctxt ~printer:(fun x -> x) expected broader_context
);
( "last_line" >:: fun ctxt ->
let contents = "// @flow\n" in
let expected = "// @flow\nAUTO332" in
let (actual, broader_context, _) =
Autocomplete_sigil.add_canonical None contents 2 0
in
let (actual, broader_context, _) = Autocomplete_sigil.add None contents 2 0 in
assert_equal ~ctxt ~printer:(fun x -> x) expected actual;
let expected = "// @flow\nAUTO332" in
assert_equal ~ctxt ~printer:(fun x -> x) expected broader_context
Expand Down
23 changes: 1 addition & 22 deletions src/services/autocomplete/autocomplete_sigil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,6 @@ let sigil = "AUTO332"

let sigil_len = String.length sigil

let add contents line column =
let line = line - 1 in
let contents_with_sigil =
Line.transform_nth contents line (fun line_str ->
let length = String.length line_str in
if length >= column then
let start = String.sub line_str 0 column in
let end_ = String.sub line_str column (length - column) in
start ^ sigil ^ end_
else
line_str
)
in
let f (_, x, _) = x in
let default = "" in
( contents_with_sigil,
Base.Option.value_map ~f ~default (Line.split_nth contents_with_sigil (line - 1))
^ Base.Option.value_map ~f ~default (Line.split_nth contents_with_sigil line)
^ Base.Option.value_map ~f ~default (Line.split_nth contents_with_sigil (line + 1))
)

module Canonical = struct
type token = {
cursor: Loc.t;
Expand Down Expand Up @@ -73,7 +52,7 @@ end
* in restoring the results of `Autocomplete_js.process_location` to a form that
* can be further processed by AutocompleteServices_js.
*)
let add_canonical source contents loc_line column =
let add source contents loc_line column =
let line = loc_line - 1 in
let (contents_with_sigil, canon_token) =
match Line.split_nth contents line with
Expand Down
5 changes: 1 addition & 4 deletions src/services/autocomplete/autocomplete_sigil.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*)

val add : string -> int -> int -> string * string

module Canonical : sig
type token

Expand All @@ -15,8 +13,7 @@ module Canonical : sig
val to_relative_token : canon:token option -> string -> string
end

val add_canonical :
File_key.t option -> string -> int -> int -> string * string * Canonical.token option
val add : File_key.t option -> string -> int -> int -> string * string * Canonical.token option

val remove_from_loc : canon:Canonical.token option -> Loc.t -> Loc.t

Expand Down

0 comments on commit 60d9126

Please sign in to comment.