@@ -1530,6 +1530,8 @@ let rec extractType ~env ~package (t : Types.type_expr) =
1530
1530
Some
1531
1531
(Tvariant
1532
1532
{env; constructors; variantName = name.txt; variantDecl = decl})
1533
+ | Some (env , {item = {kind = Record fields } } ) ->
1534
+ Some (Trecord {env; fields; typeExpr = t})
1533
1535
| _ -> None )
1534
1536
| Ttuple expressions -> Some (Tuple (env, expressions, t))
1535
1537
| Tvariant {row_fields} ->
@@ -1568,7 +1570,7 @@ let printConstructorArgs argsLen ~asSnippet =
1568
1570
else " "
1569
1571
1570
1572
let completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
1571
- ~expandOption =
1573
+ ~expandOption ~ includeLocalValues =
1572
1574
let namesUsed = Hashtbl. create 10 in
1573
1575
let rec completeTypedValueInner t ~env ~full ~prefix ~expandOption =
1574
1576
let items =
@@ -1643,10 +1645,17 @@ let completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
1643
1645
~insert Text:(printConstructorArgs numExprs ~as Snippet:true )
1644
1646
~kind: (Value typ) ~env () ;
1645
1647
]
1648
+ | Some (Trecord {env; fields; typeExpr} ) ->
1649
+ fields
1650
+ |> List. map (fun (field : field ) ->
1651
+ Completion. create ~name: field.fname.txt
1652
+ ~kind: (Field (field, typeExpr |> Shared. typeToString))
1653
+ ~env )
1654
+ |> filterItems ~prefix
1646
1655
| _ -> []
1647
1656
in
1648
1657
(* Include all values and modules in completion if there's a prefix, not otherwise *)
1649
- if prefix = " " then items
1658
+ if prefix = " " || includeLocalValues = false then items
1650
1659
else
1651
1660
items
1652
1661
@ completionForExportedValues ~env: envWhereCompletionStarted ~prefix
@@ -1740,6 +1749,13 @@ let rec resolveNestedPattern typ ~env ~package ~nested =
1740
1749
match List. nth_opt tupleItems itemNum with
1741
1750
| None -> None
1742
1751
| Some typ -> typ |> resolveNestedPattern ~env ~package ~nested )
1752
+ | Completable. PRecordField {fieldName} , Some (Trecord {env; fields} ) -> (
1753
+ match
1754
+ fields
1755
+ |> List. find_opt (fun (field : field ) -> field.fname.txt = fieldName)
1756
+ with
1757
+ | None -> None
1758
+ | Some {typ} -> typ |> resolveNestedPattern ~env ~package ~nested )
1743
1759
| _ -> None )
1744
1760
1745
1761
let processCompletable ~debug ~full ~scope ~env ~pos ~forHover
@@ -1805,7 +1821,7 @@ let processCompletable ~debug ~full ~scope ~env ~pos ~forHover
1805
1821
| Some (_ , typ , env ) ->
1806
1822
typ
1807
1823
|> completeTypedValue ~env ~env WhereCompletionStarted ~full ~prefix
1808
- ~expand Option:true )
1824
+ ~expand Option:true ~include LocalValues: true )
1809
1825
| Cdecorator prefix ->
1810
1826
let mkDecorator (name , docstring ) =
1811
1827
{(Completion. create ~name ~kind: (Label " " ) ~env ) with docstring}
@@ -2070,11 +2086,11 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
2070
2086
| Some (Optional _ , typ ) ->
2071
2087
typ
2072
2088
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
2073
- ~expandOption :true
2089
+ ~expandOption :true ~ includeLocalValues : true
2074
2090
| Some ((Unlabelled _ | Labelled _ ), typ ) ->
2075
2091
typ
2076
2092
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
2077
- ~expandOption :false )
2093
+ ~expandOption :false ~ includeLocalValues : true )
2078
2094
| CnamedArg (cp , prefix , identsSeen ) ->
2079
2095
let labels =
2080
2096
match
@@ -2115,7 +2131,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
2115
2131
| Some (typ , env ) ->
2116
2132
typ
2117
2133
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
2118
- ~expandOption :false
2134
+ ~expandOption :false ~ includeLocalValues : false
2119
2135
| None -> [] )
2120
2136
| Cpattern {typ; prefix; nested = Some nested } -> (
2121
2137
let envWhereCompletionStarted = env in
@@ -2131,5 +2147,5 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
2131
2147
| Some (typ , env ) ->
2132
2148
typ
2133
2149
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
2134
- ~expandOption :false )
2150
+ ~expandOption :false ~ includeLocalValues : false )
2135
2151
| None -> [] )
0 commit comments