@@ -535,7 +535,7 @@ let f (x : t) = x
535
535
{
536
536
" edits" : [
537
537
{
538
- " newText" : " match x with Foo _ -> _ | Bar _ -> _\n " ,
538
+ " newText" : " match x with | Foo _ -> _ | Bar _ -> _" ,
539
539
" range" : {
540
540
" end" : { " character" : 17 , " line" : 2 },
541
541
" start" : { " character" : 16 , " line" : 2 }
@@ -927,6 +927,90 @@ let f (x: q) =
927
927
|}]
928
928
;;
929
929
930
+ let % expect_test " can destruct on sub-expression" =
931
+ let source =
932
+ {ocaml|
933
+ let defered_peek x = if x > = 0 then Some (`Foo x) else None
934
+ let job_reader = 10
935
+
936
+ let _ = defered_peek job_reader
937
+ | ocaml}
938
+ in
939
+ let range =
940
+ let start = Position. create ~line: 4 ~character: 8 in
941
+ let end_ = Position. create ~line: 4 ~character: 31 in
942
+ Range. create ~start ~end_
943
+ in
944
+ print_code_actions source range ~filter: (find_action " destruct (enumerate cases)" );
945
+ [% expect
946
+ {|
947
+ Code actions :
948
+ {
949
+ " edit" : {
950
+ " documentChanges" : [
951
+ {
952
+ " edits" : [
953
+ {
954
+ " newText" : " match defered_peek job_reader with | None -> _ | Some _ -> _" ,
955
+ " range" : {
956
+ " end" : { " character" : 31 , " line" : 4 },
957
+ " start" : { " character" : 8 , " line" : 4 }
958
+ }
959
+ }
960
+ ],
961
+ " textDocument" : { " uri" : " file:///foo.ml" , " version" : 0 }
962
+ }
963
+ ]
964
+ },
965
+ " isPreferred" : false ,
966
+ " kind" : " destruct (enumerate cases)" ,
967
+ " title" : " Destruct (enumerate cases)"
968
+ }
969
+ |}]
970
+ ;;
971
+
972
+ let % expect_test " can destruct on sub-expression that need parenthesis" =
973
+ let source =
974
+ {ocaml|
975
+ let defered_peek x = if x > = 0 then Some (`Foo x) else None
976
+ let job_reader = 10
977
+
978
+ let _ = defered_peek job_reader
979
+ | ocaml}
980
+ in
981
+ let range =
982
+ let start = Position. create ~line: 4 ~character: 21 in
983
+ let end_ = Position. create ~line: 4 ~character: 31 in
984
+ Range. create ~start ~end_
985
+ in
986
+ print_code_actions source range ~filter: (find_action " destruct (enumerate cases)" );
987
+ [% expect
988
+ {|
989
+ Code actions :
990
+ {
991
+ " edit" : {
992
+ " documentChanges" : [
993
+ {
994
+ " edits" : [
995
+ {
996
+ " newText" : " (match job_reader with | 0 -> _ | _ -> _)" ,
997
+ " range" : {
998
+ " end" : { " character" : 31 , " line" : 4 },
999
+ " start" : { " character" : 21 , " line" : 4 }
1000
+ }
1001
+ }
1002
+ ],
1003
+ " textDocument" : { " uri" : " file:///foo.ml" , " version" : 0 }
1004
+ }
1005
+ ]
1006
+ },
1007
+ " isPreferred" : false ,
1008
+ " kind" : " destruct (enumerate cases)" ,
1009
+ " title" : " Destruct (enumerate cases)"
1010
+ }
1011
+ |}]
1012
+ ;;
1013
+
930
1014
let % expect_test " can infer module interfaces" =
931
1015
let impl_source =
932
1016
{ocaml|
0 commit comments