@@ -18,12 +18,13 @@ import { NullState } from 'vs/editor/common/languages/nullTokenize';
18
18
import { AutoIndentOnPaste , IndentationToSpacesCommand , IndentationToTabsCommand } from 'vs/editor/contrib/indentation/browser/indentation' ;
19
19
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor' ;
20
20
import { testCommand } from 'vs/editor/test/browser/testCommand' ;
21
- import { javascriptIndentationRules } from 'vs/editor/test/common/modes/supports/javascriptIndentationRules ' ;
22
- import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules ' ;
21
+ import { javascriptIndentationRules , phpIndentationRules , rubyIndentationRules } from 'vs/editor/test/common/modes/supports/indentationRules ' ;
22
+ import { javascriptOnEnterRules , phpOnEnterRules } from 'vs/editor/test/common/modes/supports/onEnterRules ' ;
23
23
24
24
enum Language {
25
25
TypeScript ,
26
- Ruby
26
+ Ruby ,
27
+ PHP
27
28
}
28
29
29
30
function testIndentationToSpacesCommand ( lines : string [ ] , selection : Selection , tabSize : number , expectedLines : string [ ] , expectedSelection : Selection ) : void {
@@ -66,10 +67,18 @@ function registerLanguageConfiguration(instantiationService: TestInstantiationSe
66
67
[ '[' , ']' ] ,
67
68
[ '(' , ')' ]
68
69
] ,
69
- indentationRules : {
70
- decreaseIndentPattern : / ^ \s * ( [ } \] ] ( [ , ) ] ? \s * ( # | $ ) | \. [ a - z A - Z _ ] \w * \b ) | ( e n d | r e s c u e | e n s u r e | e l s e | e l s i f ) \b | ( i n | w h e n ) \s ) / ,
71
- increaseIndentPattern : / ^ \s * ( ( b e g i n | c l a s s | ( p r i v a t e | p r o t e c t e d ) \s + d e f | d e f | e l s e | e l s i f | e n s u r e | f o r | i f | m o d u l e | r e s c u e | u n l e s s | u n t i l | w h e n | i n | w h i l e | c a s e ) | ( [ ^ # ] * \s d o \b ) | ( [ ^ # ] * = \s * ( c a s e | i f | u n l e s s ) ) ) \b ( [ ^ # \{ ; ] | ( \" | ' | \/ ) .* \4) * ( # .* ) ? $ / ,
72
- } ,
70
+ indentationRules : rubyIndentationRules ,
71
+ } ) ) ;
72
+ break ;
73
+ case Language . PHP :
74
+ disposables . add ( languageConfigurationService . register ( languageId , {
75
+ brackets : [
76
+ [ '{' , '}' ] ,
77
+ [ '[' , ']' ] ,
78
+ [ '(' , ')' ]
79
+ ] ,
80
+ indentationRules : phpIndentationRules ,
81
+ onEnterRules : phpOnEnterRules
73
82
} ) ) ;
74
83
break ;
75
84
}
@@ -606,6 +615,66 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => {
606
615
} ) ;
607
616
} ) ;
608
617
618
+ test ( 'issue #43244: indent when lambda arrow function is detected, outdent when end is reached' , ( ) => {
619
+
620
+ // https://github.com/microsoft/vscode/issues/43244
621
+
622
+ const model = createTextModel ( [
623
+ 'const array = [1, 2, 3, 4, 5];' ,
624
+ 'array.map(_)'
625
+ ] . join ( '\n' ) , languageId , { } ) ;
626
+ disposables . add ( model ) ;
627
+
628
+ withTestCodeEditor ( model , { autoIndent : "full" } , ( editor , viewModel , instantiationService ) => {
629
+ registerLanguage ( instantiationService , languageId , Language . TypeScript , disposables ) ;
630
+ editor . setSelection ( new Selection ( 2 , 12 , 2 , 12 ) ) ;
631
+ viewModel . type ( "\n" , 'keyboard' ) ;
632
+ assert . strictEqual ( model . getValue ( ) , [
633
+ 'const array = [1, 2, 3, 4, 5];' ,
634
+ 'array.map(_' ,
635
+ ' ' ,
636
+ ')'
637
+ ] . join ( '\n' ) ) ;
638
+ } ) ;
639
+ } ) ;
640
+
641
+ test ( 'issue #43244: incorrect indentation after if/for/while without braces' , ( ) => {
642
+
643
+ // https://github.com/microsoft/vscode/issues/43244
644
+
645
+ const model = createTextModel ( [
646
+ 'function f() {' ,
647
+ ' if (condition)' ,
648
+ '}'
649
+ ] . join ( '\n' ) , languageId , { } ) ;
650
+ disposables . add ( model ) ;
651
+
652
+ withTestCodeEditor ( model , { autoIndent : "full" } , ( editor , viewModel , instantiationService ) => {
653
+
654
+ registerLanguage ( instantiationService , languageId , Language . TypeScript , disposables ) ;
655
+ editor . setSelection ( new Selection ( 2 , 19 , 2 , 19 ) ) ;
656
+ viewModel . type ( "\n" , 'keyboard' ) ;
657
+ assert . strictEqual ( model . getValue ( ) , [
658
+ 'function f() {' ,
659
+ ' if (condition)' ,
660
+ ' ' ,
661
+ '}' ,
662
+ ] . join ( '\n' ) ) ;
663
+
664
+ viewModel . type ( "return;" ) ;
665
+ viewModel . type ( "\n" , 'keyboard' ) ;
666
+ assert . strictEqual ( model . getValue ( ) , [
667
+ 'function f() {' ,
668
+ ' if (condition)' ,
669
+ ' return;' ,
670
+ ' ' ,
671
+ '}' ,
672
+ ] . join ( '\n' ) ) ;
673
+ } ) ;
674
+ } ) ;
675
+
676
+ // Failing tests...
677
+
609
678
test . skip ( 'issue #40115: keep indentation when added' , ( ) => {
610
679
611
680
// https://github.com/microsoft/vscode/issues/40115
@@ -663,41 +732,6 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => {
663
732
} ) ;
664
733
} ) ;
665
734
666
- test ( 'issue #43244: incorrect indentation after if/for/while without braces' , ( ) => {
667
-
668
- // https://github.com/microsoft/vscode/issues/43244
669
-
670
- const model = createTextModel ( [
671
- 'function f() {' ,
672
- ' if (condition)' ,
673
- '}'
674
- ] . join ( '\n' ) , languageId , { } ) ;
675
- disposables . add ( model ) ;
676
-
677
- withTestCodeEditor ( model , { autoIndent : "full" } , ( editor , viewModel , instantiationService ) => {
678
-
679
- registerLanguage ( instantiationService , languageId , Language . TypeScript , disposables ) ;
680
- editor . setSelection ( new Selection ( 2 , 19 , 2 , 19 ) ) ;
681
- viewModel . type ( "\n" , 'keyboard' ) ;
682
- assert . strictEqual ( model . getValue ( ) , [
683
- 'function f() {' ,
684
- ' if (condition)' ,
685
- ' ' ,
686
- '}' ,
687
- ] . join ( '\n' ) ) ;
688
-
689
- viewModel . type ( "return;" ) ;
690
- viewModel . type ( "\n" , 'keyboard' ) ;
691
- assert . strictEqual ( model . getValue ( ) , [
692
- 'function f() {' ,
693
- ' if (condition)' ,
694
- ' return;' ,
695
- ' ' ,
696
- '}' ,
697
- ] . join ( '\n' ) ) ;
698
- } ) ;
699
- } ) ;
700
-
701
735
test . skip ( 'issue #208232: incorrect indentation inside of comments' , ( ) => {
702
736
703
737
// https://github.com/microsoft/vscode/issues/208232
@@ -871,28 +905,6 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => {
871
905
} ) ;
872
906
} ) ;
873
907
874
- test ( 'issue #43244: indent when lambda arrow function is detected, outdent when end is reached' , ( ) => {
875
-
876
- // https://github.com/microsoft/vscode/issues/43244
877
-
878
- const model = createTextModel ( [
879
- 'const array = [1, 2, 3, 4, 5];' ,
880
- 'array.map(_)'
881
- ] . join ( '\n' ) , languageId , { } ) ;
882
- disposables . add ( model ) ;
883
-
884
- withTestCodeEditor ( model , { autoIndent : "full" } , ( editor , viewModel , instantiationService ) => {
885
- registerLanguage ( instantiationService , languageId , Language . TypeScript , disposables ) ;
886
- editor . setSelection ( new Selection ( 2 , 12 , 2 , 12 ) ) ;
887
- viewModel . type ( "\n" , 'keyboard' ) ;
888
- assert . strictEqual ( model . getValue ( ) , [
889
- 'const array = [1, 2, 3, 4, 5];' ,
890
- 'array.map(_' ,
891
- ' ' ,
892
- ')'
893
- ] . join ( '\n' ) ) ;
894
- } ) ;
895
- } ) ;
896
908
897
909
// Add tests for:
898
910
// https://github.com/microsoft/vscode/issues/88638
@@ -918,6 +930,8 @@ suite('Auto Indent On Type - Ruby', () => {
918
930
919
931
test ( 'issue #198350: in or when incorrectly match non keywords for Ruby' , ( ) => {
920
932
933
+ // https://github.com/microsoft/vscode/issues/198350
934
+
921
935
const model = createTextModel ( "" , languageId , { } ) ;
922
936
disposables . add ( model ) ;
923
937
@@ -938,4 +952,66 @@ suite('Auto Indent On Type - Ruby', () => {
938
952
assert . strictEqual ( model . getValue ( ) , " # in " ) ;
939
953
} ) ;
940
954
} ) ;
955
+
956
+ // Failing tests...
957
+
958
+ test . skip ( 'issue #199846: in or when incorrectly match non keywords for Ruby' , ( ) => {
959
+
960
+ // https://github.com/microsoft/vscode/issues/199846
961
+ // explanation: happening because the # is detected probably as a comment
962
+
963
+ const model = createTextModel ( "" , languageId , { } ) ;
964
+ disposables . add ( model ) ;
965
+
966
+ withTestCodeEditor ( model , { autoIndent : "full" } , ( editor , viewModel , instantiationService ) => {
967
+
968
+ registerLanguage ( instantiationService , languageId , Language . Ruby , disposables ) ;
969
+
970
+ viewModel . type ( "method('#foo') do" ) ;
971
+ viewModel . type ( "\n" , 'keyboard' ) ;
972
+ assert . strictEqual ( model . getValue ( ) , [
973
+ "method('#foo') do" ,
974
+ " "
975
+ ] . join ( '\n' ) ) ;
976
+ } ) ;
977
+ } ) ;
978
+ } ) ;
979
+
980
+ suite ( 'Auto Indent On Type - PHP' , ( ) => {
981
+
982
+ const languageId = "php-test" ;
983
+ let disposables : DisposableStore ;
984
+
985
+ setup ( ( ) => {
986
+ disposables = new DisposableStore ( ) ;
987
+ } ) ;
988
+
989
+ teardown ( ( ) => {
990
+ disposables . dispose ( ) ;
991
+ } ) ;
992
+
993
+ ensureNoDisposablesAreLeakedInTestSuite ( ) ;
994
+
995
+ test ( 'temp issue because there should be at least one passing test in a suite' , ( ) => {
996
+ assert . ok ( true ) ;
997
+ } ) ;
998
+
999
+ test . skip ( 'issue #199050: should not indent after { detected in a string' , ( ) => {
1000
+
1001
+ // https://github.com/microsoft/vscode/issues/199050
1002
+
1003
+ const model = createTextModel ( "$phrase = preg_replace('#(\{1|%s).*#su', '', $phrase);" , languageId , { } ) ;
1004
+ disposables . add ( model ) ;
1005
+
1006
+ withTestCodeEditor ( model , { autoIndent : "full" } , ( editor , viewModel , instantiationService ) => {
1007
+
1008
+ registerLanguage ( instantiationService , languageId , Language . PHP , disposables ) ;
1009
+ editor . setSelection ( new Selection ( 1 , 54 , 1 , 54 ) ) ;
1010
+ viewModel . type ( "\n" , 'keyboard' ) ;
1011
+ assert . strictEqual ( model . getValue ( ) , [
1012
+ "$phrase = preg_replace('#(\{1|%s).*#su', '', $phrase);" ,
1013
+ ""
1014
+ ] . join ( '\n' ) ) ;
1015
+ } ) ;
1016
+ } ) ;
941
1017
} ) ;
0 commit comments