Skip to content

Commit 80100e4

Browse files
mheibermeta-codesync[bot]
authored andcommitted
Add isNamed field to Glean Parameter schema
Summary: ## What Add support for Hack named parameters: ``` function foo(named int $x): void {} ``` The type checker and runtime already support named parameters, behind a flag. ## Why So users get an accurate and informative CodeHub experience and Glean querying experience. ## How I made this stack I asked Claude to take inspiration from how we did support for `readonly` parameters, since the representation in our AST for `readonly` modifier and `named` modifier is identical. Reviewed By: donsbot Differential Revision: D94913061 fbshipit-source-id: b065125b52cc1b6df7b41a786ebef8be64a8d849
1 parent b101600 commit 80100e4

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

hphp/hack/src/typing/write_symbol_info/build_fact.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ let signature
6767
type_info = type_xref;
6868
readonly =
6969
Option.map ~f:(fun _ -> ReadonlyKind.Readonly) p.param_readonly;
70+
named = Option.map ~f:(fun _ -> NamedKind.Named) p.param_named;
7071
}
7172
in
7273
let parameters = List.map params ~f:param in

hphp/hack/src/typing/write_symbol_info/glean/hack.ml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3523,6 +3523,24 @@ end = struct
35233523

35243524
end
35253525

3526+
and NamedKind: sig
3527+
type t =
3528+
| Named
3529+
3530+
[@@deriving ord]
3531+
3532+
val to_json : t -> json
3533+
end = struct
3534+
type t =
3535+
| Named
3536+
3537+
[@@deriving ord]
3538+
3539+
let rec to_json = function
3540+
| Named -> JSON_Number (string_of_int 0)
3541+
3542+
end
3543+
35263544
and ContainerDeclaration: sig
35273545
type t =
35283546
| Class_ of ClassDeclaration.t
@@ -3606,6 +3624,7 @@ and Parameter: sig
36063624
attributes: UserAttribute.t list;
36073625
type_info: TypeInfo.t option;
36083626
readonly: ReadonlyKind.t option;
3627+
named: NamedKind.t option;
36093628
}
36103629
[@@deriving ord]
36113630

@@ -3620,10 +3639,11 @@ end = struct
36203639
attributes: UserAttribute.t list;
36213640
type_info: TypeInfo.t option;
36223641
readonly: ReadonlyKind.t option;
3642+
named: NamedKind.t option;
36233643
}
36243644
[@@deriving ord]
36253645

3626-
let rec to_json {name; type_; is_inout; is_variadic; default_value; attributes; type_info; readonly} =
3646+
let rec to_json {name; type_; is_inout; is_variadic; default_value; attributes; type_info; readonly; named} =
36273647
let fields = [
36283648
("name", Name.to_json name);
36293649
("isInout", JSON_Bool is_inout);
@@ -3646,6 +3666,10 @@ end = struct
36463666
match readonly with
36473667
| None -> fields
36483668
| Some readonly -> ("readonly", ReadonlyKind.to_json readonly) :: fields in
3669+
let fields =
3670+
match named with
3671+
| None -> fields
3672+
| Some named -> ("named", NamedKind.to_json named) :: fields in
36493673
JSON_Object fields
36503674

36513675
end

0 commit comments

Comments
 (0)