Skip to content

Commit

Permalink
[flow][refactor] Separate out export_search_types from export_search
Browse files Browse the repository at this point in the history
Summary:
The goal is to make autocomplete work in try-flow.

Auto imports search, which depends on some C++ code, absolutely won't work in browser, so in this diff we did some work to separate that out. We split export search into the search parts and the types of the results. Later, we can make autocompleteService with configuration auto-import behavior only depend on export_search_types

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D55548909

fbshipit-source-id: c4f1f950ef5c06d30f47ea6d5442b321876e577d
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Apr 1, 2024
1 parent a195349 commit 9f3a9de
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 55 deletions.
10 changes: 5 additions & 5 deletions src/services/autocomplete/autocompleteService_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ let flow_text_edit_of_lsp_text_edit { Lsp.TextEdit.range; newText } =
(loc, newText)

let completion_item_of_autoimport
~typing ~src_dir ~edit_locs ~ranking_info { Export_search.name; source; kind } rank =
~typing ~src_dir ~edit_locs ~ranking_info { Export_search_types.name; source; kind } rank =
let { options; get_haste_name; get_package_info; is_package_file; ast; _ } = typing in
match
Lsp_import_edits.text_edits_of_import
Expand Down Expand Up @@ -810,7 +810,7 @@ let append_completion_items_of_autoimports
let auto_imports_items_rev =
Base.List.foldi
~init:[]
~f:(fun i acc { Export_search.search_result = auto_import; score; weight } ->
~f:(fun i acc { Export_search_types.search_result = auto_import; score; weight } ->
let rank =
(* after builtins *)
if ac_options.imports_ranked_usage then
Expand All @@ -820,7 +820,7 @@ let append_completion_items_of_autoimports
(* if not sorted server-side, use a constant sort text *)
200
in
let { Export_search.name; kind; source = _ } = auto_import in
let { Export_search_types.name; kind; source = _ } = auto_import in
if is_reserved name kind || Base.Hash_set.mem locals name then
(* exclude reserved words and already-defined locals, because they can't be imported
without aliasing them, which we can't do automatically in autocomplete. for example,
Expand Down Expand Up @@ -981,7 +981,7 @@ let autocomplete_id
(items_rev, true, false)
else
let locals = set_of_locals ~f:(fun ((name, _docs_and_tags), _ty) -> name) identifiers in
let { Export_search.results = auto_imports; is_incomplete } =
let { Export_search_types.results = auto_imports; is_incomplete } =
let options =
{
default_autoimport_options with
Expand Down Expand Up @@ -1462,7 +1462,7 @@ let autocomplete_unqualified_type
add_locals ~f:(fun ((name, _docs_and_tags), _ty) -> name) value_identifiers set;
set
in
let { Export_search.results = auto_imports; is_incomplete } =
let { Export_search_types.results = auto_imports; is_incomplete } =
let (before, _after) = Autocomplete_sigil.remove token in
let options =
{
Expand Down
7 changes: 1 addition & 6 deletions src/services/export/index/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
(wrapped false)
(libraries
flow_typing
flow_typing_type
fuzzy_path
flow_procs
flow_state_readers
flow_state_heaps_parsing
flow_monitor_rpc)
flow_typing_type)
(preprocess
(pps ppx_deriving.std)))
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

open OUnit2
open Export_search
open Export_search_types

let default_type = Export_index.DefaultType

Expand Down
3 changes: 1 addition & 2 deletions src/services/export/search/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
flow_typing_type
fuzzy_path
flow_procs
flow_state_readers
flow_state_heaps_parsing
flow_search_types
flow_monitor_rpc)
(preprocess
(pps ppx_deriving.std)))
22 changes: 2 additions & 20 deletions src/services/export/search/export_search.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,14 @@
* LICENSE file in the root directory of this source tree.
*)

open Export_search_types

type t = {
index: Export_index.t;
value_matcher: Fuzzy_path.t;
type_matcher: Fuzzy_path.t;
}

type search_result = {
name: string;
source: Export_index.source;
kind: Export_index.kind;
}
[@@deriving show]

type search_result_scored = {
search_result: search_result;
score: int;
weight: int;
}
[@@deriving show]

type search_results = {
results: search_result_scored list;
is_incomplete: bool;
}
[@@deriving show]

type search_options = Fuzzy_path.options = {
first_match_can_be_weak: bool;
num_threads: int;
Expand Down
24 changes: 2 additions & 22 deletions src/services/export/search/export_search.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,6 @@ type search_options = Fuzzy_path.options = {
weighted: bool;
}

type search_result = {
name: string;
source: Export_index.source;
kind: Export_index.kind;
}
[@@deriving show]

type search_result_scored = {
search_result: search_result;
score: int;
weight: int;
}
[@@deriving show]

type search_results = {
results: search_result_scored list;
is_incomplete: bool;
}
[@@deriving show]

val init : Export_index.t -> t

val merge : Export_index.t -> t -> t
Expand All @@ -46,9 +26,9 @@ val subtract_count : Export_index.t -> t -> t

val default_options : search_options

val search_values : ?options:search_options -> string -> t -> search_results
val search_values : ?options:search_options -> string -> t -> Export_search_types.search_results

val search_types : ?options:search_options -> string -> t -> search_results
val search_types : ?options:search_options -> string -> t -> Export_search_types.search_results

val get : string -> t -> int Export_index.ExportMap.t

Expand Down
7 changes: 7 additions & 0 deletions src/services/export/search/types/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(library
(name flow_search_types)
(wrapped false)
(libraries
flow_index)
(preprocess
(pps ppx_deriving.std)))
26 changes: 26 additions & 0 deletions src/services/export/search/types/export_search_types.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)

type search_result = {
name: string;
source: Export_index.source;
kind: Export_index.kind;
}
[@@deriving show]

type search_result_scored = {
search_result: search_result;
score: int;
weight: int;
}
[@@deriving show]

type search_results = {
results: search_result_scored list;
is_incomplete: bool;
}
[@@deriving show]

0 comments on commit 9f3a9de

Please sign in to comment.