@@ -1427,16 +1427,39 @@ let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
1427
1427
| Cjsx (componentPath , prefix , identsSeen ) ->
1428
1428
let labels =
1429
1429
match componentPath @ [" make" ] |> findTypeOfValue with
1430
- | Some (typ , _env ) ->
1431
- let rec getFields (texp : Types.type_expr ) =
1430
+ | Some (typ , make_env ) ->
1431
+ let rec getFieldsV3 (texp : Types.type_expr ) =
1432
1432
match texp.desc with
1433
1433
| Tfield (name , _ , t1 , t2 ) ->
1434
- let fields = t2 |> getFields in
1434
+ let fields = t2 |> getFieldsV3 in
1435
1435
if name = " children" then fields else (name, t1) :: fields
1436
- | Tlink te | Tsubst te | Tpoly (te , [] ) -> te |> getFields
1436
+ | Tlink te | Tsubst te | Tpoly (te , [] ) -> te |> getFieldsV3
1437
1437
| Tvar None -> []
1438
1438
| _ -> []
1439
1439
in
1440
+ let getFieldsV4 ~path ~typeArgs =
1441
+ match References. digConstructor ~env: make_env ~package path with
1442
+ | Some
1443
+ ( _env,
1444
+ {
1445
+ item =
1446
+ {
1447
+ decl =
1448
+ {
1449
+ type_kind = Type_record (labelDecls, _repr);
1450
+ type_params = typeParams;
1451
+ };
1452
+ };
1453
+ } ) ->
1454
+ labelDecls
1455
+ |> List. map (fun (ld : Types.label_declaration ) ->
1456
+ let name = Ident. name ld.ld_id in
1457
+ let t =
1458
+ ld.ld_type |> instantiateType ~type Params ~type Args
1459
+ in
1460
+ (name, t))
1461
+ | _ -> []
1462
+ in
1440
1463
let rec getLabels (t : Types.type_expr ) =
1441
1464
match t.desc with
1442
1465
| Tlink t1 | Tsubst t1 | Tpoly (t1 , [] ) -> getLabels t1
@@ -1449,9 +1472,14 @@ let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
1449
1472
},
1450
1473
_,
1451
1474
_ ) ->
1452
- getFields tObj
1475
+ (* JSX V3 *)
1476
+ getFieldsV3 tObj
1477
+ | Tarrow (Nolabel , {desc = Tconstr (path, typeArgs, _)}, _, _)
1478
+ when Path. last path = " props" ->
1479
+ (* JSX V4 *)
1480
+ getFieldsV4 ~path ~type Args
1453
1481
| Tconstr
1454
- ( path ,
1482
+ ( clPath ,
1455
1483
[
1456
1484
{
1457
1485
desc =
@@ -1461,8 +1489,14 @@ let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
1461
1489
_;
1462
1490
],
1463
1491
_ )
1464
- when Path. name path = " React.componentLike" ->
1465
- getFields tObj
1492
+ when Path. name clPath = " React.componentLike" ->
1493
+ (* JSX V3 external or interface *)
1494
+ getFieldsV3 tObj
1495
+ | Tconstr (clPath, [{desc = Tconstr (path, typeArgs, _)}; _], _)
1496
+ when Path. name clPath = " React.componentLike"
1497
+ && Path. last path = " props" ->
1498
+ (* JSX V4 external or interface *)
1499
+ getFieldsV4 ~path ~type Args
1466
1500
| _ -> []
1467
1501
in
1468
1502
typ |> getLabels
@@ -1480,6 +1514,7 @@ let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
1480
1514
(labels
1481
1515
|> List. filter (fun (name , _t ) ->
1482
1516
Utils. startsWith name prefix
1517
+ && name <> " key"
1483
1518
&& (forHover || not (List. mem name identsSeen)))
1484
1519
|> List. map mkLabel)
1485
1520
@ keyLabels
0 commit comments