@@ -1477,7 +1477,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
1477
1477
else None )
1478
1478
| None -> [] )
1479
1479
| None -> [] )
1480
- | CPPipe {contextPath = cp ; id = funNamePrefix ; lhsLoc} -> (
1480
+ | CPPipe {contextPath = cp ; id = funNamePrefix ; lhsLoc; inJsx } -> (
1481
1481
match
1482
1482
cp
1483
1483
|> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
@@ -1584,7 +1584,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
1584
1584
| None -> None
1585
1585
in
1586
1586
match completionPath with
1587
- | Some completionPath ->
1587
+ | Some completionPath -> (
1588
1588
let completionPathMinusOpens =
1589
1589
completionPath
1590
1590
|> removeRawOpens package.opens
@@ -1599,14 +1599,50 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
1599
1599
|> getCompletionsForPath ~completion Context:Value ~exact: false
1600
1600
~package ~opens ~all Files ~pos ~env ~scope
1601
1601
in
1602
- completions
1603
- |> List. map (fun (completion : Completion.t ) ->
1604
- {
1605
- completion with
1606
- name = completionName completion.name;
1607
- env
1608
- (* Restore original env for the completion after x->foo()... *) ;
1609
- })
1602
+ let completions =
1603
+ completions
1604
+ |> List. map (fun (completion : Completion.t ) ->
1605
+ {
1606
+ completion with
1607
+ name = completionName completion.name;
1608
+ env
1609
+ (* Restore original env for the completion after x->foo()... *) ;
1610
+ })
1611
+ in
1612
+ (* We add React element functions to the completion if we're in a JSX context *)
1613
+ let forJsxCompletion =
1614
+ match (inJsx, getTypePath typ) with
1615
+ | true , Some (Path. Pident id ) when Ident. name id = " int" -> Some " int"
1616
+ | true , Some (Path. Pident id ) when Ident. name id = " float" ->
1617
+ Some " float"
1618
+ | true , Some (Path. Pident id ) when Ident. name id = " string" ->
1619
+ Some " string"
1620
+ | true , Some (Path. Pident id ) when Ident. name id = " array" ->
1621
+ (* Make sure the array contains React.element *)
1622
+ let isReactElementArray =
1623
+ match typ |> extractType ~env ~package with
1624
+ | Some (Tarray (_env , payload )) -> (
1625
+ match
1626
+ payload |> getTypePath |> Option. map pathIdentToString
1627
+ with
1628
+ | Some "React.element" -> true
1629
+ | _ -> false )
1630
+ | _ -> false
1631
+ in
1632
+ if isReactElementArray then Some " array" else None
1633
+ | _ -> None
1634
+ in
1635
+ match forJsxCompletion with
1636
+ | Some builtinNameToComplete
1637
+ when checkName builtinNameToComplete ~prefix: funNamePrefix
1638
+ ~exact: false ->
1639
+ [
1640
+ Completion. create
1641
+ ~name: (" React." ^ builtinNameToComplete)
1642
+ ~kind: (Value typ) ~env ;
1643
+ ]
1644
+ @ completions
1645
+ | _ -> completions)
1610
1646
| None -> [] )
1611
1647
| None -> [] )
1612
1648
| CTuple ctxPaths ->
0 commit comments