@@ -1502,6 +1502,13 @@ let rec extractType ~env ~package (t : Types.type_expr) =
1502
1502
| Ttuple expressions -> Some (Tuple (env, expressions))
1503
1503
| _ -> None
1504
1504
1505
+ let filterItems items ~prefix =
1506
+ if prefix = " " then items
1507
+ else
1508
+ items
1509
+ |> List. filter (fun (item : Completion.t ) ->
1510
+ Utils. startsWith item.name prefix)
1511
+
1505
1512
let completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
1506
1513
~expandOption =
1507
1514
let namesUsed = Hashtbl. create 10 in
@@ -1511,65 +1518,45 @@ let completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
1511
1518
| Some (Toption (env , typ )) when expandOption ->
1512
1519
typ |> completeTypedValueInner ~env ~full ~prefix ~expand Option:false
1513
1520
| Some (Tbool env ) ->
1514
- let items =
1515
- [
1516
- Completion. create ~name: " true"
1517
- ~kind: (Label (t |> Shared. typeToString))
1518
- ~env ;
1519
- Completion. create ~name: " false"
1520
- ~kind: (Label (t |> Shared. typeToString))
1521
- ~env ;
1522
- ]
1523
- in
1524
- if prefix = " " then items
1525
- else
1526
- items
1527
- |> List. filter (fun (item : Completion.t ) ->
1528
- Utils. startsWith item.name prefix)
1521
+ [
1522
+ Completion. create ~name: " true"
1523
+ ~kind: (Label (t |> Shared. typeToString))
1524
+ ~env ;
1525
+ Completion. create ~name: " false"
1526
+ ~kind: (Label (t |> Shared. typeToString))
1527
+ ~env ;
1528
+ ]
1529
+ |> filterItems ~prefix
1529
1530
| Some (Tvariant {env; constructors; variantDecl; variantName} ) ->
1530
- let items =
1531
- constructors
1532
- |> List. filter_map (fun (constructor : Constructor.t ) ->
1533
- if
1534
- prefix <> " "
1535
- && not (Utils. startsWith constructor.cname.txt prefix)
1536
- then None
1537
- else
1538
- Some
1539
- (Completion. create
1540
- ~name:
1541
- (constructor.cname.txt
1542
- ^
1543
- if constructor.args |> List. length > 0 then
1544
- " ("
1545
- ^ (constructor.args
1546
- |> List. map (fun _ -> " _" )
1547
- |> String. concat " , " )
1548
- ^ " )"
1549
- else " " )
1550
- ~kind:
1551
- (Constructor
1552
- ( constructor,
1553
- variantDecl |> Shared. declToString variantName ))
1554
- ~env ))
1555
- in
1556
- items
1531
+ constructors
1532
+ |> List. map (fun (constructor : Constructor.t ) ->
1533
+ Completion. create
1534
+ ~name:
1535
+ (constructor.cname.txt
1536
+ ^
1537
+ if constructor.args |> List. length > 0 then
1538
+ " ("
1539
+ ^ (constructor.args
1540
+ |> List. map (fun _ -> " _" )
1541
+ |> String. concat " , " )
1542
+ ^ " )"
1543
+ else " " )
1544
+ ~kind:
1545
+ (Constructor
1546
+ ( constructor,
1547
+ variantDecl |> Shared. declToString variantName ))
1548
+ ~env )
1549
+ |> filterItems ~prefix
1557
1550
| Some (Toption (env , t )) ->
1558
- let items =
1559
- [
1560
- Completion. create ~name: " None"
1561
- ~kind: (Label (t |> Shared. typeToString))
1562
- ~env ;
1563
- Completion. create ~name: " Some(_)"
1564
- ~kind: (Label (t |> Shared. typeToString))
1565
- ~env ;
1566
- ]
1567
- in
1568
- if prefix = " " then items
1569
- else
1570
- items
1571
- |> List. filter (fun (item : Completion.t ) ->
1572
- Utils. startsWith item.name prefix)
1551
+ [
1552
+ Completion. create ~name: " None"
1553
+ ~kind: (Label (t |> Shared. typeToString))
1554
+ ~env ;
1555
+ Completion. create ~name: " Some(_)"
1556
+ ~kind: (Label (t |> Shared. typeToString))
1557
+ ~env ;
1558
+ ]
1559
+ |> filterItems ~prefix
1573
1560
| _ -> []
1574
1561
in
1575
1562
(* Include all values and modules in completion if there's a prefix, not otherwise *)
0 commit comments