@@ -631,9 +631,7 @@ let completionToItem
631
631
| Some detail -> detail)
632
632
~docstring
633
633
in
634
- if ! Cfg. supportsSnippets then
635
- {item with sortText; insertText; insertTextFormat; filterText}
636
- else item
634
+ {item with sortText; insertText; insertTextFormat; filterText}
637
635
638
636
let completionsGetTypeEnv = function
639
637
| {Completion. kind = Value typ ; env} :: _ -> Some (typ, env)
@@ -1021,14 +1019,13 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1021
1019
|> String. concat " ."
1022
1020
in
1023
1021
[
1024
- Completion. createWithSnippet ~ name ~kind: (Value typ) ~env
1022
+ Completion. create name ~includes Snippets: true ~kind: (Value typ) ~env
1025
1023
~sort Text:" A"
1026
1024
~docstring:
1027
1025
[
1028
1026
" Turns `" ^ builtinNameToComplete
1029
1027
^ " ` into a JSX element so it can be used inside of JSX." ;
1030
- ]
1031
- () ;
1028
+ ];
1032
1029
]
1033
1030
@ completions
1034
1031
| _ -> completions)
@@ -1274,7 +1271,6 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1274
1271
~full ~prefix ~completionContext ~mode (t : SharedTypes.completionType ) =
1275
1272
let emptyCase = emptyCase ~mode in
1276
1273
let printConstructorArgs = printConstructorArgs ~mode in
1277
- let createWithSnippet = Completion. createWithSnippet ?typeArgContext in
1278
1274
let create = Completion. create ?typeArgContext in
1279
1275
match t with
1280
1276
| TtypeT {env; path} ->
@@ -1326,14 +1322,15 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1326
1322
if valueWithTypeT typeExpr then
1327
1323
getCompletionName name
1328
1324
|> Option. map (fun name ->
1329
- createWithSnippet ~ name ~insert Text:name ~kind: ( Value typeExpr)
1330
- ~env () )
1325
+ create name ~includes Snippets: true ~insert Text:name
1326
+ ~kind: ( Value typeExpr) ~env )
1331
1327
else if fnReturnsTypeT typeExpr then
1332
1328
getCompletionName name
1333
1329
|> Option. map (fun name ->
1334
- createWithSnippet
1335
- ~name: (Printf. sprintf " %s()" name)
1336
- ~insert Text:(name ^ " ($0)" ) ~kind: (Value typeExpr) ~env () )
1330
+ create
1331
+ (Printf. sprintf " %s()" name)
1332
+ ~includes Snippets:true ~insert Text:(name ^ " ($0)" )
1333
+ ~kind: (Value typeExpr) ~env )
1337
1334
else None
1338
1335
in
1339
1336
let completionItems =
@@ -1353,8 +1350,8 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1353
1350
match path with
1354
1351
| Pdot (Pdot (Pident m , "Re" , _ ), "t" , _ ) when Ident. name m = " Js" ->
1355
1352
(* regexps *)
1356
- createWithSnippet ~name: " %re()" ~insert Text:" %re(\" /$0/g\" )"
1357
- ~kind: (Label " Regular expression" ) ~env ()
1353
+ create " %re()" ~insert Text:" %re(\" /$0/g\" )" ~includes Snippets: true
1354
+ ~kind: (Label " Regular expression" ) ~env
1358
1355
:: completionItems
1359
1356
| _ -> completionItems
1360
1357
in
@@ -1375,29 +1372,28 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1375
1372
| InlineRecord _ -> 1
1376
1373
| Args args -> List. length args
1377
1374
in
1378
- createWithSnippet ?deprecated:constructor.deprecated
1379
- ~name:
1380
- (constructor.cname.txt
1381
- ^ printConstructorArgs numArgs ~as Snippet:false )
1375
+ create ?deprecated:constructor.deprecated ~includes Snippets:true
1376
+ (constructor.cname.txt
1377
+ ^ printConstructorArgs numArgs ~as Snippet:false )
1382
1378
~insert Text:
1383
1379
(constructor.cname.txt
1384
1380
^ printConstructorArgs numArgs ~as Snippet:true )
1385
1381
~kind:
1386
1382
(Constructor
1387
1383
(constructor, variantDecl |> Shared. declToString variantName))
1388
- ~env () )
1384
+ ~env )
1389
1385
|> filterItems ~prefix
1390
1386
| Tpolyvariant {env; constructors; typeExpr} ->
1391
1387
if Debug. verbose () then
1392
1388
print_endline " [complete_typed_value]--> Tpolyvariant" ;
1393
1389
constructors
1394
1390
|> List. map (fun (constructor : polyVariantConstructor ) ->
1395
- createWithSnippet
1396
- ~name:
1397
- ( " # " ^ constructor.displayName
1398
- ^ printConstructorArgs
1399
- ( List. length constructor.args )
1400
- ~as Snippet: false )
1391
+ create
1392
+ ( " # " ^ constructor.displayName
1393
+ ^ printConstructorArgs
1394
+ ( List. length constructor.args)
1395
+ ~as Snippet: false )
1396
+ ~includes Snippets: true
1401
1397
~insert Text:
1402
1398
((if Utils. startsWith prefix " #" then " " else " #" )
1403
1399
^ constructor.displayName
@@ -1407,7 +1403,7 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1407
1403
~kind:
1408
1404
(PolyvariantConstructor
1409
1405
(constructor, typeExpr |> Shared. typeToString))
1410
- ~env () )
1406
+ ~env )
1411
1407
|> filterItems
1412
1408
~prefix: (if Utils. startsWith prefix " #" then prefix else " #" ^ prefix)
1413
1409
| Toption (env , t ) ->
@@ -1436,19 +1432,17 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1436
1432
in
1437
1433
let noneCase = Completion. create " None" ~kind: (kindFromInnerType t) ~env in
1438
1434
let someAnyCase =
1439
- createWithSnippet ~name: " Some(_)" ~kind: (kindFromInnerType t) ~env
1435
+ create " Some(_)" ~includes Snippets: true ~kind: (kindFromInnerType t) ~env
1440
1436
~insert Text:(Printf. sprintf " Some(%s)" (emptyCase 1 ))
1441
- ()
1442
1437
in
1443
1438
let completions =
1444
1439
match completionContext with
1445
1440
| Some (Completable. CameFromRecordField fieldName ) ->
1446
1441
[
1447
- createWithSnippet
1448
- ~name: (" Some(" ^ fieldName ^ " )" )
1449
- ~kind: (kindFromInnerType t) ~env
1450
- ~insert Text:(" Some(" ^ fieldName ^ " )$0" )
1451
- () ;
1442
+ create
1443
+ (" Some(" ^ fieldName ^ " )" )
1444
+ ~includes Snippets:true ~kind: (kindFromInnerType t) ~env
1445
+ ~insert Text:(" Some(" ^ fieldName ^ " )$0" );
1452
1446
someAnyCase;
1453
1447
noneCase;
1454
1448
]
@@ -1498,24 +1492,21 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1498
1492
})
1499
1493
in
1500
1494
let okAnyCase =
1501
- createWithSnippet ~name: " Ok(_)" ~kind: (Value okType) ~env
1495
+ create " Ok(_)" ~includes Snippets: true ~kind: (Value okType) ~env
1502
1496
~insert Text:(Printf. sprintf " Ok(%s)" (emptyCase 1 ))
1503
- ()
1504
1497
in
1505
1498
let errorAnyCase =
1506
- createWithSnippet ~name: " Error(_)" ~kind: (Value errorType) ~env
1499
+ create " Error(_)" ~includes Snippets: true ~kind: (Value errorType) ~env
1507
1500
~insert Text:(Printf. sprintf " Error(%s)" (emptyCase 1 ))
1508
- ()
1509
1501
in
1510
1502
let completions =
1511
1503
match completionContext with
1512
1504
| Some (Completable. CameFromRecordField fieldName ) ->
1513
1505
[
1514
- createWithSnippet
1515
- ~name: (" Ok(" ^ fieldName ^ " )" )
1516
- ~kind: (Value okType) ~env
1517
- ~insert Text:(" Ok(" ^ fieldName ^ " )$0" )
1518
- () ;
1506
+ create
1507
+ (" Ok(" ^ fieldName ^ " )" )
1508
+ ~includes Snippets:true ~kind: (Value okType) ~env
1509
+ ~insert Text:(" Ok(" ^ fieldName ^ " )$0" );
1519
1510
okAnyCase;
1520
1511
errorAnyCase;
1521
1512
]
@@ -1527,10 +1518,11 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1527
1518
if Debug. verbose () then print_endline " [complete_typed_value]--> Tuple" ;
1528
1519
let numExprs = List. length exprs in
1529
1520
[
1530
- createWithSnippet
1531
- ~name: (printConstructorArgs numExprs ~as Snippet:false )
1521
+ create
1522
+ (printConstructorArgs numExprs ~as Snippet:false )
1523
+ ~includes Snippets:true
1532
1524
~insert Text:(printConstructorArgs numExprs ~as Snippet:true )
1533
- ~kind: (Value typ) ~env () ;
1525
+ ~kind: (Value typ) ~env ;
1534
1526
]
1535
1527
| Trecord {env; fields} as extractedType -> (
1536
1528
if Debug. verbose () then print_endline " [complete_typed_value]--> Trecord" ;
@@ -1564,16 +1556,14 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1564
1556
| _ ->
1565
1557
if prefix = " " then
1566
1558
[
1567
- createWithSnippet ~name: " {}"
1568
- ~insert Text:(if ! Cfg. supportsSnippets then " {$0}" else " {}" )
1569
- ~sort Text:" A"
1559
+ create " {}" ~includes Snippets:true ~insert Text:" {$0}" ~sort Text:" A"
1570
1560
~kind:
1571
1561
(ExtractedType
1572
1562
( extractedType,
1573
1563
match mode with
1574
1564
| Pattern _ -> `Type
1575
1565
| Expression -> `Value ))
1576
- ~env () ;
1566
+ ~env ;
1577
1567
]
1578
1568
else [] )
1579
1569
| TinlineRecord {env; fields} -> (
@@ -1591,18 +1581,15 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1591
1581
| _ ->
1592
1582
if prefix = " " then
1593
1583
[
1594
- createWithSnippet ~name: " {}"
1595
- ~insert Text:(if ! Cfg. supportsSnippets then " {$0}" else " {}" )
1596
- ~sort Text:" A" ~kind: (Label " Inline record" ) ~env () ;
1584
+ create " {}" ~includes Snippets:true ~insert Text:" {$0}" ~sort Text:" A"
1585
+ ~kind: (Label " Inline record" ) ~env ;
1597
1586
]
1598
1587
else [] )
1599
1588
| Tarray (env , typ ) ->
1600
1589
if Debug. verbose () then print_endline " [complete_typed_value]--> Tarray" ;
1601
1590
if prefix = " " then
1602
1591
[
1603
- createWithSnippet ~name: " []"
1604
- ~insert Text:(if ! Cfg. supportsSnippets then " [$0]" else " []" )
1605
- ~sort Text:" A"
1592
+ create " []" ~includes Snippets:true ~insert Text:" [$0]" ~sort Text:" A"
1606
1593
~kind:
1607
1594
(match typ with
1608
1595
| ExtractedType typ ->
@@ -1612,19 +1599,17 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1612
1599
| Pattern _ -> `Type
1613
1600
| Expression -> `Value )
1614
1601
| TypeExpr typ -> Value typ)
1615
- ~env () ;
1602
+ ~env ;
1616
1603
]
1617
1604
else []
1618
1605
| Tstring env ->
1619
1606
if Debug. verbose () then print_endline " [complete_typed_value]--> Tstring" ;
1620
1607
if prefix = " " then
1621
1608
[
1622
- createWithSnippet ~name: " \"\" "
1623
- ~insert Text:(if ! Cfg. supportsSnippets then " \" $0\" " else " \"\" " )
1624
- ~sort Text:" A"
1609
+ create " \"\" " ~includes Snippets:true ~insert Text:" \" $0\" " ~sort Text:" A"
1625
1610
~kind:
1626
1611
(Value (Ctype. newconstr (Path. Pident (Ident. create " string" )) [] ))
1627
- ~env () ;
1612
+ ~env ;
1628
1613
]
1629
1614
else []
1630
1615
| Tfunction {env; typ; args; uncurried; returnType}
@@ -1673,14 +1658,11 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
1673
1658
in
1674
1659
let asyncPrefix = if isAsync then " async " else " " in
1675
1660
[
1676
- createWithSnippet
1677
- ~name: (asyncPrefix ^ mkFnArgs ~as Snippet:false ^ " => {}" )
1678
- ~insert Text:
1679
- (asyncPrefix
1680
- ^ mkFnArgs ~as Snippet:! Cfg. supportsSnippets
1681
- ^ " => "
1682
- ^ if ! Cfg. supportsSnippets then " {$0}" else " {}" )
1683
- ~sort Text:" A" ~kind: (Value typ) ~env () ;
1661
+ create
1662
+ (asyncPrefix ^ mkFnArgs ~as Snippet:false ^ " => {}" )
1663
+ ~includes Snippets:true
1664
+ ~insert Text:(asyncPrefix ^ mkFnArgs ~as Snippet:true ^ " => " ^ " {$0}" )
1665
+ ~sort Text:" A" ~kind: (Value typ) ~env ;
1684
1666
]
1685
1667
| Tfunction _ ->
1686
1668
if Debug. verbose () then
@@ -1952,8 +1934,8 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
1952
1934
| Cdecorator prefix ->
1953
1935
let mkDecorator (name , docstring , maybeInsertText ) =
1954
1936
{
1955
- (Completion. createWithSnippet ~ name ~kind: (Label " " ) ~env
1956
- ?insertText:maybeInsertText () )
1937
+ (Completion. create name ~includes Snippets: true ~kind: (Label " " ) ~env
1938
+ ?insertText:maybeInsertText)
1957
1939
with
1958
1940
docstring;
1959
1941
}
0 commit comments