Skip to content

Commit

Permalink
[flow][autocomplete] only strings in tparams_rev in process_location_…
Browse files Browse the repository at this point in the history
…result

Summary:
AutocompleteService_js only uses tparams_rev for the names of the parameters. Instead of computing a list of `Type.typeparam`s and then accessing just their names, this diff changes `process_request_searcher` to only gather the names of the type parameters (as strings) from the beginning. It does this by instantiating `type_parameter_mapper_generic` with `'P` as `string`.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D54910377

fbshipit-source-id: b1fb00243b2168161759812a4784e8c73fbd0bfb
  • Loading branch information
panagosg7 authored and facebook-github-bot committed Mar 14, 2024
1 parent 004ab0f commit 9b50c1b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/services/autocomplete/autocompleteService_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1248,8 +1248,7 @@ let utility_types =
"$Values";
]

let make_type_param ~edit_locs { Type.name; _ } =
let name = Subst_name.string_of_subst_name name in
let make_type_param ~edit_locs name =
{
AcCompletion.kind = Some Lsp.Completion.TypeParameter;
name;
Expand Down
21 changes: 19 additions & 2 deletions src/services/autocomplete/autocomplete_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type autocomplete_type =
| Ac_jsx_text (** JSX text child *)

type process_location_result = {
tparams_rev: Type.typeparam list;
tparams_rev: string list;
ac_loc: ALoc.t;
token: string;
autocomplete_type: autocomplete_type;
Expand Down Expand Up @@ -131,7 +131,24 @@ exception Found of process_location_result

class process_request_searcher (from_trigger_character : bool) (cursor : Loc.t) =
object (this)
inherit Typed_ast_finder.type_parameter_mapper as super
inherit
[ALoc.t, ALoc.t * Type.t, ALoc.t, ALoc.t * Type.t, string] Typed_ast_finder
.type_parameter_mapper_generic as super

method private loc_of_annot (loc, _) = loc

method on_loc_annot x = x

method on_type_annot (x, y) = (x, y)

method private make_typeparam tparam =
let open Flow_ast.Type.TypeParam in
let (_, { name = (_, { Flow_ast.Identifier.name; _ }); _ }) = tparam in
name

method private make_class_this _cls = "this"

method private make_declare_class_this _decl = "this"

val mutable enclosing_classes : Type.t list = []

Expand Down
2 changes: 1 addition & 1 deletion src/services/autocomplete/autocomplete_js.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type autocomplete_type =
| Ac_jsx_text (** JSX text child *)

type process_location_result = {
tparams_rev: Type.typeparam list;
tparams_rev: string list;
ac_loc: ALoc.t;
token: string;
autocomplete_type: autocomplete_type;
Expand Down

0 comments on commit 9b50c1b

Please sign in to comment.