@@ -1570,7 +1570,7 @@ let printConstructorArgs argsLen ~asSnippet =
1570
1570
else " "
1571
1571
1572
1572
let completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
1573
- ~expandOption ~includeLocalValues =
1573
+ ~expandOption ~includeLocalValues ~ completionContext =
1574
1574
let namesUsed = Hashtbl. create 10 in
1575
1575
let rec completeTypedValueInner t ~env ~full ~prefix ~expandOption =
1576
1576
let items =
@@ -1645,13 +1645,21 @@ let completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
1645
1645
~insert Text:(printConstructorArgs numExprs ~as Snippet:true )
1646
1646
~kind: (Value typ) ~env () ;
1647
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
1648
+ | Some (Trecord {env; fields; typeExpr} ) -> (
1649
+ match completionContext with
1650
+ | Some Completable. RecordField ->
1651
+ fields
1652
+ |> List. map (fun (field : field ) ->
1653
+ Completion. create ~name: field.fname.txt
1654
+ ~kind: (Field (field, typeExpr |> Shared. typeToString))
1655
+ ~env )
1656
+ |> filterItems ~prefix
1657
+ | None ->
1658
+ [
1659
+ Completion. createWithSnippet ~name: " {}"
1660
+ ~insert Text:(if ! Cfg. supportsSnippets then " {$0}" else " {}" )
1661
+ ~sort Text:" a" ~kind: (Value typeExpr) ~env () ;
1662
+ ])
1655
1663
| _ -> []
1656
1664
in
1657
1665
(* Include all values and modules in completion if there's a prefix, not otherwise *)
@@ -1742,20 +1750,22 @@ let getJsxLabels ~componentPath ~findTypeOfValue ~package =
1742
1750
1743
1751
let rec resolveNestedPattern typ ~env ~package ~nested =
1744
1752
match nested with
1745
- | [] -> Some (typ, env)
1753
+ | [] -> Some (typ, env, None )
1746
1754
| patternPath :: nested -> (
1747
1755
match (patternPath, typ |> extractType ~env ~package ) with
1748
1756
| Completable. PTupleItem {itemNum} , Some (Tuple (env , tupleItems , _ )) -> (
1749
1757
match List. nth_opt tupleItems itemNum with
1750
1758
| None -> None
1751
1759
| Some typ -> typ |> resolveNestedPattern ~env ~package ~nested )
1752
- | Completable. PRecordField {fieldName} , Some (Trecord {env; fields} ) -> (
1760
+ | PFollowRecordField {fieldName} , Some (Trecord {env; fields} ) -> (
1753
1761
match
1754
1762
fields
1755
1763
|> List. find_opt (fun (field : field ) -> field.fname.txt = fieldName)
1756
1764
with
1757
1765
| None -> None
1758
1766
| Some {typ} -> typ |> resolveNestedPattern ~env ~package ~nested )
1767
+ | PRecordBody _ , Some (Trecord {env; typeExpr} ) ->
1768
+ Some (typeExpr, env, Some Completable. RecordField )
1759
1769
| _ -> None )
1760
1770
1761
1771
let processCompletable ~debug ~full ~scope ~env ~pos ~forHover
@@ -1821,7 +1831,7 @@ let processCompletable ~debug ~full ~scope ~env ~pos ~forHover
1821
1831
| Some (_ , typ , env ) ->
1822
1832
typ
1823
1833
|> completeTypedValue ~env ~env WhereCompletionStarted ~full ~prefix
1824
- ~expand Option:true ~include LocalValues:true )
1834
+ ~expand Option:true ~include LocalValues:true ~completion Context: None )
1825
1835
| Cdecorator prefix ->
1826
1836
let mkDecorator (name , docstring ) =
1827
1837
{(Completion. create ~name ~kind: (Label " " ) ~env ) with docstring}
@@ -2086,11 +2096,11 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
2086
2096
| Some (Optional _ , typ ) ->
2087
2097
typ
2088
2098
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
2089
- ~expandOption :true ~includeLocalValues :true
2099
+ ~expandOption :true ~includeLocalValues :true ~ completionContext :None
2090
2100
| Some ((Unlabelled _ | Labelled _ ), typ ) ->
2091
2101
typ
2092
2102
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
2093
- ~expandOption :false ~includeLocalValues :true )
2103
+ ~expandOption :false ~includeLocalValues :true ~ completionContext :None )
2094
2104
| CnamedArg (cp , prefix , identsSeen ) ->
2095
2105
let labels =
2096
2106
match
@@ -2131,7 +2141,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
2131
2141
| Some (typ , env ) ->
2132
2142
typ
2133
2143
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
2134
- ~expandOption :false ~includeLocalValues :false
2144
+ ~expandOption :false ~includeLocalValues :false ~ completionContext :None
2135
2145
| None -> [] )
2136
2146
| Cpattern {typ; prefix; nested = Some nested } -> (
2137
2147
let envWhereCompletionStarted = env in
@@ -2144,8 +2154,8 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
2144
2154
| Some (typ , env ) -> (
2145
2155
match typ |> resolveNestedPattern ~env ~package :full .package ~nested with
2146
2156
| None -> []
2147
- | Some (typ , env ) ->
2157
+ | Some (typ , env , completionContext ) ->
2148
2158
typ
2149
2159
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
2150
- ~expandOption :false ~includeLocalValues :false )
2160
+ ~expandOption :false ~includeLocalValues :false ~ completionContext )
2151
2161
| None -> [] )
0 commit comments