Skip to content

Commit

Permalink
[flow][cleanup] Cleanup global find-ref and rename flag
Browse files Browse the repository at this point in the history
Summary:
They are both defaulted to true for a while now.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D57119661

fbshipit-source-id: 1097887f798d7b9ea9843d74e4de0a3cab13b4e0
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed May 8, 2024
1 parent 335cf7c commit de0a059
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 210 deletions.
2 changes: 0 additions & 2 deletions src/commands/commandUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1460,8 +1460,6 @@ let make_options
opt_autoimports_ranked_by_usage_boost_exact_match_min_length =
FlowConfig.autoimports_ranked_by_usage_boost_exact_match_min_length flowconfig;
opt_flowconfig_hash = flowconfig_hash;
opt_global_find_ref = Base.Option.value (FlowConfig.global_find_ref flowconfig) ~default:true;
opt_global_rename = Base.Option.value (FlowConfig.global_rename flowconfig) ~default:true;
opt_gc_worker =
{
Options.gc_minor_heap_size =
Expand Down
12 changes: 0 additions & 12 deletions src/commands/config/flowConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ module Opts = struct
gc_worker_space_overhead: int option; (** Gc.control's space_overhead *)
gc_worker_window_size: int option; (** Gc.control's window_size *)
generate_tests: bool;
global_find_ref: bool option;
global_rename: bool option;
haste_module_ref_prefix: string option;
haste_module_ref_prefix_LEGACY_INTEROP: string option;
haste_name_reducers: (Str.regexp * string) list;
Expand Down Expand Up @@ -212,8 +210,6 @@ module Opts = struct
gc_worker_space_overhead = None;
gc_worker_window_size = None;
generate_tests = false;
global_find_ref = None;
global_rename = None;
haste_module_ref_prefix = None;
haste_module_ref_prefix_LEGACY_INTEROP = None;
haste_name_reducers =
Expand Down Expand Up @@ -918,10 +914,6 @@ module Opts = struct
("experimental.channel_mode.windows", channel_mode_parser ~enabled:Sys.win32);
("experimental.long_lived_workers", long_lived_workers_parser ~enabled:true);
("experimental.long_lived_workers.windows", long_lived_workers_parser ~enabled:Sys.win32);
( "experimental.global_find_ref",
boolean (fun opts v -> Ok { opts with global_find_ref = Some v })
);
("experimental.global_rename", boolean (fun opts v -> Ok { opts with global_rename = Some v }));
( "experimental.multi_platform",
boolean (fun opts v -> Ok { opts with multi_platform = Some v })
);
Expand Down Expand Up @@ -1614,10 +1606,6 @@ let gc_worker_space_overhead c = c.options.Opts.gc_worker_space_overhead

let gc_worker_window_size c = c.options.Opts.gc_worker_window_size

let global_find_ref c = c.options.Opts.global_find_ref

let global_rename c = c.options.Opts.global_rename

let haste_module_ref_prefix c = c.options.Opts.haste_module_ref_prefix

let haste_module_ref_prefix_LEGACY_INTEROP c = c.options.Opts.haste_module_ref_prefix_LEGACY_INTEROP
Expand Down
4 changes: 0 additions & 4 deletions src/commands/config/flowConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ val gc_worker_space_overhead : config -> int option

val gc_worker_window_size : config -> int option

val global_find_ref : config -> bool option

val global_rename : config -> bool option

val haste_module_ref_prefix : config -> string option

val haste_module_ref_prefix_LEGACY_INTEROP : config -> string option
Expand Down
6 changes: 0 additions & 6 deletions src/common/options.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ type t = {
opt_flowconfig_name: string;
opt_format: format;
opt_gc_worker: gc_control;
opt_global_find_ref: bool;
opt_global_rename: bool;
opt_haste_module_ref_prefix: string option;
opt_haste_module_ref_prefix_LEGACY_INTEROP: string option;
opt_haste_name_reducers: (Str.regexp * string) list;
Expand Down Expand Up @@ -250,10 +248,6 @@ let format_single_quotes opts = opts.opt_format.opt_single_quotes

let gc_worker opts = opts.opt_gc_worker

let global_find_ref opts = opts.opt_global_find_ref

let global_rename opts = opts.opt_global_rename

let haste_module_ref_prefix opts = opts.opt_haste_module_ref_prefix

let haste_module_ref_prefix_LEGACY_INTEROP opts = opts.opt_haste_module_ref_prefix_LEGACY_INTEROP
Expand Down
264 changes: 78 additions & 186 deletions src/server/command_handler/commandHandler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2733,46 +2733,25 @@ let handle_persistent_find_references
~loc_of_aloc ~options ~id ~params ~metadata ~client ~profiling ~env =
let text_doc_position = params.FindReferences.loc in
let ref_to_location (_, loc) = Flow_lsp_conversions.loc_to_lsp loc |> Base.Result.ok in
if Options.global_find_ref options then
handle_global_find_references
~loc_of_aloc
~options
~id
~metadata
~client
~profiling
~env
~kind:FindRefsTypes.FindReferences
~request:(LspProt.LspToServer (RequestMessage (id, FindReferencesRequest params)))
~refs_to_lsp_result:(fun ~current_ast:_ refs ->
let result_compare (_, l1) (_, l2) = Loc.compare l1 l2 in
let locs =
refs
|> Base.List.dedup_and_sort ~compare:result_compare
|> Base.List.filter_map ~f:ref_to_location
in
FindReferencesResult locs)
text_doc_position
else
let%lwt (result, extra_data) =
map_local_find_references_results
~loc_of_aloc
~options
~client
~profiling
~env
~f:ref_to_location
text_doc_position
in
let metadata = with_data ~extra_data metadata in
match result with
| Ok result ->
let r = FindReferencesResult result in
let response = ResponseMessage (id, r) in
Lwt.return (env, LspProt.LspFromServer (Some response), metadata)
| Error reason ->
let (resp, metadata) = mk_lsp_error_response ~id:(Some id) ~reason metadata in
Lwt.return (env, resp, metadata)
handle_global_find_references
~loc_of_aloc
~options
~id
~metadata
~client
~profiling
~env
~kind:FindRefsTypes.FindReferences
~request:(LspProt.LspToServer (RequestMessage (id, FindReferencesRequest params)))
~refs_to_lsp_result:(fun ~current_ast:_ refs ->
let result_compare (_, l1) (_, l2) = Loc.compare l1 l2 in
let locs =
refs
|> Base.List.dedup_and_sort ~compare:result_compare
|> Base.List.filter_map ~f:ref_to_location
in
FindReferencesResult locs)
text_doc_position

let handle_persistent_document_highlight
~loc_of_aloc ~options ~id ~params ~metadata ~client ~profiling ~env =
Expand Down Expand Up @@ -2801,153 +2780,66 @@ let handle_persistent_document_highlight
let handle_persistent_rename ~reader ~options ~id ~params ~metadata ~client ~profiling ~env =
let Rename.{ textDocument; position; newName } = params in
let text_doc_position = TextDocumentPositionParams.{ textDocument; position } in
if Options.global_rename options then
handle_global_find_references
~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader)
~options
~id
~metadata
~client
~profiling
~env
~kind:FindRefsTypes.Rename
~request:(LspProt.LspToServer (RequestMessage (id, RenameRequest params)))
~refs_to_lsp_result:(fun ~current_ast refs ->
let (ref_map, files) =
List.fold_left
(fun (ref_map, files) (ref_kind, loc) ->
( Loc_collections.LocMap.add loc ref_kind ref_map,
loc
|> Loc.source
|> Base.Option.value_map ~default:files ~f:(fun f -> FilenameSet.add f files)
))
(Loc_collections.LocMap.empty, FilenameSet.empty)
refs
in
let asts =
files
|> FilenameSet.elements
|> Base.List.filter_map ~f:(fun filename ->
match current_ast with
| Some (ast_loc, _) when Loc.source ast_loc = Some filename -> current_ast
| _ -> Parsing_heaps.Reader.get_ast ~reader filename
)
in
let diff_of_ast ast =
Flow_ast_differ.program
ast
(RenameMapper.rename ~global:true ~targets:ref_map ~new_name:newName ast)
in
let all_diffs = Base.List.bind asts ~f:diff_of_ast in
let opts =
Js_layout_generator.
{
default_opts with
bracket_spacing = Options.format_bracket_spacing options;
single_quotes = Options.format_single_quotes options;
}
in
let changes =
Base.List.fold_right
(Replacement_printer.mk_loc_patch_ast_differ ~opts all_diffs)
~init:UriMap.empty
~f:(fun (loc, newText) acc ->
match Flow_lsp_conversions.loc_to_lsp loc |> Base.Result.ok with
| None -> acc
| Some { Location.uri; range } ->
let edits = UriMap.find_opt uri acc |> Base.Option.value ~default:[] in
let edits = { TextEdit.range; newText } :: edits in
UriMap.add uri edits acc
)
in
RenameResult { WorkspaceEdit.changes })
text_doc_position
else
let%lwt (result, extra_data) =
let (file_artifacts_opt, extra_parse_data) =
get_file_artifacts ~options ~client ~profiling ~env text_doc_position
handle_global_find_references
~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader)
~options
~id
~metadata
~client
~profiling
~env
~kind:FindRefsTypes.Rename
~request:(LspProt.LspToServer (RequestMessage (id, RenameRequest params)))
~refs_to_lsp_result:(fun ~current_ast refs ->
let (ref_map, files) =
List.fold_left
(fun (ref_map, files) (ref_kind, loc) ->
( Loc_collections.LocMap.add loc ref_kind ref_map,
loc
|> Loc.source
|> Base.Option.value_map ~default:files ~f:(fun f -> FilenameSet.add f files)
))
(Loc_collections.LocMap.empty, FilenameSet.empty)
refs
in
match file_artifacts_opt with
| Ok (Some (file_artifacts, file_key)) ->
let global = Options.global_rename options in
let%lwt (all_refs, extra_data) =
find_local_references
~loc_of_aloc:(Parsing_heaps.Reader.loc_of_aloc ~reader)
~file_artifacts
~kind:FindRefsTypes.Rename
file_key
text_doc_position
in
let (parse_artifacts, _typecheck_artifacts) = file_artifacts in
let edits =
match all_refs with
| Ok (_def_info, FindRefsTypes.FoundReferences refs) ->
let (ref_map, files) =
List.fold_left
(fun (ref_map, files) (ref_kind, loc) ->
( Loc_collections.LocMap.add loc ref_kind ref_map,
loc
|> Loc.source
|> Base.Option.value_map ~default:files ~f:(fun f -> FilenameSet.add f files)
))
(Loc_collections.LocMap.empty, FilenameSet.empty)
refs
in
let asts =
if global then
files
|> FilenameSet.elements
|> Base.List.filter_map ~f:(Parsing_heaps.Reader.get_ast ~reader)
else
match parse_artifacts with
| Types_js_types.Parse_artifacts { ast; _ } -> [ast]
in
let diff_of_ast ast =
Flow_ast_differ.program
ast
(RenameMapper.rename ~global ~targets:ref_map ~new_name:newName ast)
in
let all_diffs = Base.List.bind asts ~f:diff_of_ast in
let opts =
Js_layout_generator.
{
default_opts with
bracket_spacing = Options.format_bracket_spacing options;
single_quotes = Options.format_single_quotes options;
}
in
let changes =
Base.List.fold_right
(Replacement_printer.mk_loc_patch_ast_differ ~opts all_diffs)
~init:UriMap.empty
~f:(fun (loc, newText) acc ->
match Flow_lsp_conversions.loc_to_lsp loc |> Base.Result.ok with
| None -> acc
| Some { Location.uri; range } ->
let edits = UriMap.find_opt uri acc |> Base.Option.value ~default:[] in
let edits = { TextEdit.range; newText } :: edits in
UriMap.add uri edits acc
)
in
Ok { WorkspaceEdit.changes }
| Ok (_def_info, FindRefsTypes.NoDefinition _) ->
(* e.g. if it was requested on a place that's not even an identifier *)
Ok { WorkspaceEdit.changes = UriMap.empty }
| Error _ as err -> err
in
Lwt.return (edits, extra_data)
| Ok None -> Lwt.return (Ok { WorkspaceEdit.changes = UriMap.empty }, extra_parse_data)
| Error _ as err -> Lwt.return (err, extra_parse_data)
in
let metadata = with_data ~extra_data metadata in
match result with
| Ok result ->
let r = RenameResult result in
let response = ResponseMessage (id, r) in
Lwt.return (env, LspProt.LspFromServer (Some response), metadata)
| Error reason ->
let (resp, metadata) = mk_lsp_error_response ~id:(Some id) ~reason metadata in
Lwt.return (env, resp, metadata)
let asts =
files
|> FilenameSet.elements
|> Base.List.filter_map ~f:(fun filename ->
match current_ast with
| Some (ast_loc, _) when Loc.source ast_loc = Some filename -> current_ast
| _ -> Parsing_heaps.Reader.get_ast ~reader filename
)
in
let diff_of_ast ast =
Flow_ast_differ.program
ast
(RenameMapper.rename ~global:true ~targets:ref_map ~new_name:newName ast)
in
let all_diffs = Base.List.bind asts ~f:diff_of_ast in
let opts =
Js_layout_generator.
{
default_opts with
bracket_spacing = Options.format_bracket_spacing options;
single_quotes = Options.format_single_quotes options;
}
in
let changes =
Base.List.fold_right
(Replacement_printer.mk_loc_patch_ast_differ ~opts all_diffs)
~init:UriMap.empty
~f:(fun (loc, newText) acc ->
match Flow_lsp_conversions.loc_to_lsp loc |> Base.Result.ok with
| None -> acc
| Some { Location.uri; range } ->
let edits = UriMap.find_opt uri acc |> Base.Option.value ~default:[] in
let edits = { TextEdit.range; newText } :: edits in
UriMap.add uri edits acc
)
in
RenameResult { WorkspaceEdit.changes })
text_doc_position

let handle_persistent_coverage ~options ~id ~params ~file_input ~metadata ~client ~profiling ~env =
let textDocument = params.TypeCoverage.textDocument in
Expand Down

0 comments on commit de0a059

Please sign in to comment.