@@ -490,8 +490,8 @@ let domLabels =
490
490
let showConstructor {Constructor. cname = {txt} ; args; res} =
491
491
txt
492
492
^ (match args with
493
- | [] -> " "
494
- | _ ->
493
+ | Args [] | InlineRecord _ -> " "
494
+ | Args args ->
495
495
" ("
496
496
^ (args
497
497
|> List. map (fun (typ , _ ) -> typ |> Shared. typeToString)
@@ -1793,29 +1793,35 @@ let printConstructorArgs argsLen ~asSnippet =
1793
1793
if List. length ! args > 0 then " (" ^ (! args |> String. concat " , " ) ^ " )"
1794
1794
else " "
1795
1795
1796
- let rec completeTypedValue (t : Types.type_expr ) ~env ~full ~prefix
1796
+ let rec completeTypedValue (t : SharedTypes.completionType ) ~env ~full ~prefix
1797
1797
~completionContext =
1798
- match t |> extractType ~env ~package: full.package with
1798
+ let extractedType =
1799
+ match t with
1800
+ | TypeExpr t -> t |> extractType ~env ~package: full.package
1801
+ | InlineRecord fields -> Some (TinlineRecord {env; fields})
1802
+ in
1803
+ match extractedType with
1799
1804
| Some (Tbool env ) ->
1800
1805
[
1801
- Completion. create " true" ~kind: (Label (t |> Shared. typeToString) ) ~env ;
1802
- Completion. create " false" ~kind: (Label (t |> Shared. typeToString) ) ~env ;
1806
+ Completion. create " true" ~kind: (Label " bool " ) ~env ;
1807
+ Completion. create " false" ~kind: (Label " bool " ) ~env ;
1803
1808
]
1804
1809
|> filterItems ~prefix
1805
1810
| Some (Tvariant {env; constructors; variantDecl; variantName} ) ->
1806
1811
constructors
1807
1812
|> List. map (fun (constructor : Constructor.t ) ->
1813
+ let numArgs =
1814
+ match constructor.args with
1815
+ | InlineRecord _ -> 1
1816
+ | Args args -> List. length args
1817
+ in
1808
1818
Completion. createWithSnippet
1809
1819
~name:
1810
1820
(constructor.cname.txt
1811
- ^ printConstructorArgs
1812
- (List. length constructor.args)
1813
- ~as Snippet:false )
1821
+ ^ printConstructorArgs numArgs ~as Snippet:false )
1814
1822
~insert Text:
1815
1823
(constructor.cname.txt
1816
- ^ printConstructorArgs
1817
- (List. length constructor.args)
1818
- ~as Snippet:true )
1824
+ ^ printConstructorArgs numArgs ~as Snippet:true )
1819
1825
~kind:
1820
1826
(Constructor
1821
1827
(constructor, variantDecl |> Shared. declToString variantName))
@@ -1844,7 +1850,7 @@ let rec completeTypedValue (t : Types.type_expr) ~env ~full ~prefix
1844
1850
| Some (Toption (env , t )) ->
1845
1851
let innerType = Utils. unwrapIfOption t in
1846
1852
let expandedCompletions =
1847
- innerType
1853
+ TypeExpr innerType
1848
1854
|> completeTypedValue ~env ~full ~prefix ~completion Context
1849
1855
|> List. map (fun (c : Completion.t ) ->
1850
1856
{
@@ -1895,6 +1901,24 @@ let rec completeTypedValue (t : Types.type_expr) ~env ~full ~prefix
1895
1901
~sort Text:" A" ~kind: (Value typeExpr) ~env () ;
1896
1902
]
1897
1903
else [] )
1904
+ | Some (TinlineRecord {env; fields} ) -> (
1905
+ match completionContext with
1906
+ | Some (Completable. RecordField {seenFields} ) ->
1907
+ fields
1908
+ |> List. filter (fun (field : field ) ->
1909
+ List. mem field.fname.txt seenFields = false )
1910
+ |> List. map (fun (field : field ) ->
1911
+ Completion. create field.fname.txt ~kind: (Label " Inline record" )
1912
+ ~env )
1913
+ |> filterItems ~prefix
1914
+ | None ->
1915
+ if prefix = " " then
1916
+ [
1917
+ Completion. createWithSnippet ~name: " {}"
1918
+ ~insert Text:(if ! Cfg. supportsSnippets then " {$0}" else " {}" )
1919
+ ~sort Text:" A" ~kind: (Label " Inline record" ) ~env () ;
1920
+ ]
1921
+ else [] )
1898
1922
| Some (Tarray (env , typeExpr )) ->
1899
1923
if prefix = " " then
1900
1924
[
@@ -1917,41 +1941,52 @@ let rec completeTypedValue (t : Types.type_expr) ~env ~full ~prefix
1917
1941
| _ -> []
1918
1942
1919
1943
(* * This moves through a nested path via a set of instructions, trying to resolve the type at the end of the path. *)
1920
- let rec resolveNested typ ~env ~package ~nested =
1944
+ let rec resolveNested ( typ : completionType ) ~env ~package ~nested =
1921
1945
match nested with
1922
1946
| [] -> Some (typ, env, None )
1923
1947
| patternPath :: nested -> (
1924
- match (patternPath, typ |> extractType ~env ~package ) with
1948
+ let extractedType =
1949
+ match typ with
1950
+ | TypeExpr typ -> typ |> extractType ~env ~package
1951
+ | InlineRecord fields -> Some (TinlineRecord {env; fields})
1952
+ in
1953
+ match (patternPath, extractedType) with
1925
1954
| Completable. NTupleItem {itemNum} , Some (Tuple (env , tupleItems , _ )) -> (
1926
1955
match List. nth_opt tupleItems itemNum with
1927
1956
| None -> None
1928
- | Some typ -> typ |> resolveNested ~env ~package ~nested )
1929
- | NFollowRecordField {fieldName} , Some (Trecord {env; fields} ) -> (
1957
+ | Some typ -> TypeExpr typ |> resolveNested ~env ~package ~nested )
1958
+ | ( NFollowRecordField {fieldName},
1959
+ Some (TinlineRecord {env; fields} | Trecord {env; fields} ) ) -> (
1930
1960
match
1931
1961
fields
1932
1962
|> List. find_opt (fun (field : field ) -> field.fname.txt = fieldName)
1933
1963
with
1934
1964
| None -> None
1935
1965
| Some {typ; optional} ->
1936
1966
let typ = if optional then Utils. unwrapIfOption typ else typ in
1937
- typ |> resolveNested ~env ~package ~nested )
1967
+ TypeExpr typ |> resolveNested ~env ~package ~nested )
1938
1968
| NRecordBody {seenFields} , Some (Trecord {env; typeExpr} ) ->
1939
- Some (typeExpr, env, Some (Completable. RecordField {seenFields}))
1969
+ Some (TypeExpr typeExpr, env, Some (Completable. RecordField {seenFields}))
1970
+ | NRecordBody {seenFields} , Some (TinlineRecord {env; fields} ) ->
1971
+ Some
1972
+ (InlineRecord fields, env, Some (Completable. RecordField {seenFields}))
1940
1973
| ( NVariantPayload {constructorName = " Some" ; itemNum = 0 },
1941
1974
Some (Toption (env, typ)) ) ->
1942
- typ |> resolveNested ~env ~package ~nested
1975
+ TypeExpr typ |> resolveNested ~env ~package ~nested
1943
1976
| ( NVariantPayload {constructorName; itemNum},
1944
1977
Some (Tvariant {env; constructors}) ) -> (
1945
1978
match
1946
1979
constructors
1947
1980
|> List. find_opt (fun (c : Constructor.t ) ->
1948
1981
c.cname.txt = constructorName)
1949
1982
with
1950
- | None -> None
1951
- | Some constructor -> (
1952
- match List. nth_opt constructor.args itemNum with
1983
+ | Some {args = Args args } -> (
1984
+ match List. nth_opt args itemNum with
1953
1985
| None -> None
1954
- | Some (typ , _ ) -> typ |> resolveNested ~env ~package ~nested ))
1986
+ | Some (typ , _ ) -> TypeExpr typ |> resolveNested ~env ~package ~nested )
1987
+ | Some {args = InlineRecord fields } when itemNum = 0 ->
1988
+ InlineRecord fields |> resolveNested ~env ~package ~nested
1989
+ | _ -> None )
1955
1990
| ( NPolyvariantPayload {constructorName; itemNum},
1956
1991
Some (Tpolyvariant {env; constructors}) ) -> (
1957
1992
match
@@ -1963,9 +1998,9 @@ let rec resolveNested typ ~env ~package ~nested =
1963
1998
| Some constructor -> (
1964
1999
match List. nth_opt constructor.args itemNum with
1965
2000
| None -> None
1966
- | Some typ -> typ |> resolveNested ~env ~package ~nested ))
2001
+ | Some typ -> TypeExpr typ |> resolveNested ~env ~package ~nested ))
1967
2002
| NArray , Some (Tarray (env , typ )) ->
1968
- typ |> resolveNested ~env ~package ~nested
2003
+ TypeExpr typ |> resolveNested ~env ~package ~nested
1969
2004
| _ -> None )
1970
2005
1971
2006
let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
@@ -2301,7 +2336,9 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
2301
2336
|> completionsGetTypeEnv
2302
2337
with
2303
2338
| Some (typ , env ) -> (
2304
- match typ |> resolveNested ~env ~package: full.package ~nested with
2339
+ match
2340
+ TypeExpr typ |> resolveNested ~env ~package: full.package ~nested
2341
+ with
2305
2342
| None -> fallbackOrEmpty ()
2306
2343
| Some (typ , env , completionContext ) ->
2307
2344
let items =
@@ -2318,7 +2355,9 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
2318
2355
with
2319
2356
| None -> []
2320
2357
| Some (typ , env ) -> (
2321
- match typ |> resolveNested ~env ~package: full.package ~nested with
2358
+ match
2359
+ TypeExpr typ |> resolveNested ~env ~package: full.package ~nested
2360
+ with
2322
2361
| None -> []
2323
2362
| Some (typ , env , completionContext ) -> (
2324
2363
let items =
0 commit comments