Skip to content

Commit

Permalink
[flow][refactor] Use enclosing_node_mapper instead of `type_paramet…
Browse files Browse the repository at this point in the history
…er_mapper` where we don't care about tparams_rev at all

Summary:
In the migrated callsites, `tparams_rev` is just ignored.

Changelog: [internal]

Reviewed By: gkz

Differential Revision: D56639063

fbshipit-source-id: c67fe290443aa7f18704d247b82cdff4cd073b73
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Apr 26, 2024
1 parent aa450c0 commit 64f82cf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
43 changes: 25 additions & 18 deletions src/commands/glean/gleanRunner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ module DocumentationFullspanMap = struct
end

class member_searcher add_member =
object (this)
inherit Typed_ast_finder.type_parameter_mapper as super
object (_this)
inherit
[ALoc.t, ALoc.t * Type.t, ALoc.t, ALoc.t * Type.t] Typed_ast_finder.enclosing_node_mapper as super

method! on_loc_annot x = x
method on_loc_annot x = x

method! on_type_annot x = x
method on_type_annot x = x

method! member annot member =
let open Ast.Expression.Member in
let { _object = ((_, type_), _); property; _ } = member in
(match property with
| PropertyIdentifier ((aloc, _), Ast.Identifier.{ name; _ }) ->
this#annot_with_tparams (fun ~tparams_rev:_ -> add_member ~type_ ~aloc ~name)
| PropertyIdentifier ((aloc, _), Ast.Identifier.{ name; _ }) -> add_member ~type_ ~aloc ~name
| _ -> ());
super#member annot member
end
Expand All @@ -83,7 +83,9 @@ class type_reference_searcher add_reference =
super#generic_identifier_type git
end

module Type_ = Type
open GleanSchema
module Type = Type_

let remove_dot_flow_suffix = function
| Module.File file ->
Expand Down Expand Up @@ -552,59 +554,64 @@ let local_declaration_references ~root ~write_root ~scope_info =
Scope_builder.Api.DefMap.fold add_uses_of_def uses_of_all_defs []

class declaration_info_collector ~scope_info ~reader ~add_var_info ~add_member_info ~add_type_info =
object (this)
inherit Typed_ast_finder.type_parameter_mapper as super
object (_this)
inherit
[ALoc.t, ALoc.t * Type.t, ALoc.t, ALoc.t * Type.t] Typed_ast_finder.enclosing_node_mapper as super

method on_loc_annot x = x

method on_type_annot x = x

method! t_identifier (((aloc, type_), Ast.Identifier.{ name; _ }) as ident) =
let loc = Parsing_heaps.Reader.loc_of_aloc ~reader aloc in
if
Scope_builder.Api.is_local_use scope_info loc && Scope_builder.Api.use_is_def scope_info loc
then
this#annot_with_tparams add_var_info name loc type_;
add_var_info name loc type_;
ident

method! object_key_identifier (((aloc, type_), Ast.Identifier.{ name; _ }) as ident) =
let loc = Parsing_heaps.Reader.loc_of_aloc ~reader aloc in
this#annot_with_tparams add_member_info name loc type_;
add_member_info name loc type_;
ident

method! type_alias _loc alias =
let Ast.Statement.TypeAlias.{ id = ((aloc, type_), Ast.Identifier.{ name; _ }); _ } = alias in
let loc = Parsing_heaps.Reader.loc_of_aloc ~reader aloc in
this#annot_with_tparams add_type_info name loc type_;
add_type_info name loc type_;
alias

method! opaque_type _loc otype =
let Ast.Statement.OpaqueType.{ id = ((aloc, type_), Ast.Identifier.{ name; _ }); _ } =
otype
in
let loc = Parsing_heaps.Reader.loc_of_aloc ~reader aloc in
this#annot_with_tparams add_type_info name loc type_;
add_type_info name loc type_;
otype

method! interface _loc iface =
let Ast.Statement.Interface.{ id = ((aloc, type_), Ast.Identifier.{ name; _ }); _ } = iface in
let loc = Parsing_heaps.Reader.loc_of_aloc ~reader aloc in
this#annot_with_tparams add_type_info name loc type_;
add_type_info name loc type_;
iface

method! class_identifier (((aloc, type_), Ast.Identifier.{ name; _ }) as ident) =
let loc = Parsing_heaps.Reader.loc_of_aloc ~reader aloc in
this#annot_with_tparams add_type_info name loc type_;
add_type_info name loc type_;
super#class_identifier ident

method! enum_declaration enum =
let open Ast.Statement.EnumDeclaration in
let { id = ((aloc, type_), Ast.Identifier.{ name; _ }); body = (_, body); _ } = enum in
let loc = Parsing_heaps.Reader.loc_of_aloc ~reader aloc in
this#annot_with_tparams add_type_info name loc type_;
add_type_info name loc type_;
let defaulted_member (aloc, { DefaultedMember.id = (_, Ast.Identifier.{ name; _ }); _ }) =
let loc = Parsing_heaps.Reader.loc_of_aloc ~reader aloc in
this#annot_with_tparams add_member_info name loc type_
add_member_info name loc type_
in
let initialized_member (aloc, { InitializedMember.id = (_, Ast.Identifier.{ name; _ }); _ }) =
let loc = Parsing_heaps.Reader.loc_of_aloc ~reader aloc in
this#annot_with_tparams add_member_info name loc type_
add_member_info name loc type_
in
(match body with
| BooleanBody BooleanBody.{ members; _ } -> Base.List.iter members ~f:initialized_member
Expand All @@ -626,7 +633,7 @@ let module_documentations ~root ~write_root ~ast ~file : Hh_json.json list =

let declaration_infos ~root ~write_root ~scope_info ~file ~file_sig ~cx ~reader ~typed_ast ~ast =
let infos = ref [] in
let add_info kind ~tparams_rev:_ name loc type_ = infos := ((kind, name, loc), type_) :: !infos in
let add_info kind name loc (type_ : Type.t) = infos := ((kind, name, loc), type_) :: !infos in
let add_var_info = add_info `Declaration in
let add_member_info = add_info `MemberDeclaration in
let add_type_info = add_info `TypeDeclaration in
Expand Down
11 changes: 7 additions & 4 deletions src/services/type_info/signature_help.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ module Callee_finder = struct

class finder ~loc_of_aloc ~(cx : Context.t) (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] Typed_ast_finder.enclosing_node_mapper as super

method on_loc_annot x = x

method on_type_annot x = x

method covers_target loc = Reason.in_range cursor (loc_of_aloc loc)

Expand Down Expand Up @@ -182,9 +187,7 @@ module Callee_finder = struct
let active_parameter = find_argument ~loc_of_aloc cursor arguments 0 in
let loc = loc_of_aloc callee_loc in
let type_ = get_callee_type () in
this#annot_with_tparams (fun ~tparams_rev:_ ->
raise (Found (Some { type_; active_parameter; loc }))
)
raise (Found (Some { type_; active_parameter; loc }))
else
recurse ()

Expand Down

0 comments on commit 64f82cf

Please sign in to comment.