@@ -572,206 +572,176 @@ suite('TextModelWithTokens regression tests', () => {
572
572
} ) ;
573
573
574
574
suite ( 'TextModel.getLineIndentGuide' , ( ) => {
575
- function assertIndentGuides ( lines : [ number , string ] [ ] ) : void {
576
- let text = lines . map ( l => l [ 1 ] ) . join ( '\n' ) ;
575
+ function assertIndentGuides ( lines : [ number , number , number , number , string ] [ ] ) : void {
576
+ let text = lines . map ( l => l [ 4 ] ) . join ( '\n' ) ;
577
577
let model = TextModel . createFromString ( text ) ;
578
578
579
579
let actualIndents = model . getLinesIndentGuides ( 1 , model . getLineCount ( ) ) ;
580
580
581
- let actual : [ number , string ] [ ] = [ ] ;
581
+ let actual : [ number , number , number , number , string ] [ ] = [ ] ;
582
582
for ( let line = 1 ; line <= model . getLineCount ( ) ; line ++ ) {
583
- actual [ line - 1 ] = [ actualIndents [ line - 1 ] , model . getLineContent ( line ) ] ;
583
+ const activeIndentGuide = model . getActiveIndentGuide ( line , 1 , model . getLineCount ( ) ) ;
584
+ actual [ line - 1 ] = [ actualIndents [ line - 1 ] , activeIndentGuide . startLineNumber , activeIndentGuide . endLineNumber , activeIndentGuide . indent , model . getLineContent ( line ) ] ;
584
585
}
585
586
586
587
assert . deepEqual ( actual , lines ) ;
587
588
588
- // Also test getActiveIndentGuide
589
- for ( let lineNumber = 1 ; lineNumber <= model . getLineCount ( ) ; lineNumber ++ ) {
590
- let startLineNumber = lineNumber ;
591
- let endLineNumber = lineNumber ;
592
- let indent = actualIndents [ lineNumber - 1 ] ;
593
-
594
- if ( indent !== 0 ) {
595
- for ( let i = lineNumber - 1 ; i >= 1 ; i -- ) {
596
- const currIndent = actualIndents [ i - 1 ] ;
597
- if ( currIndent >= indent ) {
598
- startLineNumber = i ;
599
- } else {
600
- break ;
601
- }
602
- }
603
- for ( let i = lineNumber + 1 ; i <= model . getLineCount ( ) ; i ++ ) {
604
- const currIndent = actualIndents [ i - 1 ] ;
605
- if ( currIndent >= indent ) {
606
- endLineNumber = i ;
607
- } else {
608
- break ;
609
- }
610
- }
611
- }
612
-
613
- const expected = { startLineNumber, endLineNumber, indent } ;
614
- const actual = model . getActiveIndentGuide ( lineNumber , 1 , model . getLineCount ( ) ) ;
615
-
616
- assert . deepEqual ( actual , expected , `line number ${ lineNumber } ` ) ;
617
- }
618
-
619
589
model . dispose ( ) ;
620
590
}
621
591
622
592
test ( 'getLineIndentGuide one level' , ( ) => {
623
593
assertIndentGuides ( [
624
- [ 0 , 'A' ] ,
625
- [ 1 , ' A' ] ,
626
- [ 1 , ' A' ] ,
627
- [ 1 , ' A' ] ,
594
+ [ 0 , 1 , 1 , 0 , 'A' ] ,
595
+ [ 1 , 2 , 4 , 1 , ' A' ] ,
596
+ [ 1 , 2 , 4 , 1 , ' A' ] ,
597
+ [ 1 , 2 , 4 , 1 , ' A' ] ,
628
598
] ) ;
629
599
} ) ;
630
600
631
601
test ( 'getLineIndentGuide two levels' , ( ) => {
632
602
assertIndentGuides ( [
633
- [ 0 , 'A' ] ,
634
- [ 1 , ' A' ] ,
635
- [ 1 , ' A' ] ,
636
- [ 1 , ' A' ] ,
637
- [ 1 , ' A' ] ,
603
+ [ 0 , 1 , 1 , 0 , 'A' ] ,
604
+ [ 1 , 2 , 5 , 1 , ' A' ] ,
605
+ [ 1 , 2 , 5 , 1 , ' A' ] ,
606
+ [ 1 , 2 , 5 , 1 , ' A' ] ,
607
+ [ 1 , 2 , 5 , 1 , ' A' ] ,
638
608
] ) ;
639
609
} ) ;
640
610
641
611
test ( 'getLineIndentGuide three levels' , ( ) => {
642
612
assertIndentGuides ( [
643
- [ 0 , 'A' ] ,
644
- [ 1 , ' A' ] ,
645
- [ 1 , ' A' ] ,
646
- [ 2 , ' A' ] ,
647
- [ 0 , 'A' ] ,
613
+ [ 0 , 1 , 1 , 0 , 'A' ] ,
614
+ [ 1 , 2 , 4 , 1 , ' A' ] ,
615
+ [ 1 , 2 , 4 , 1 , ' A' ] ,
616
+ [ 2 , 4 , 4 , 2 , ' A' ] ,
617
+ [ 0 , 5 , 5 , 0 , 'A' ] ,
648
618
] ) ;
649
619
} ) ;
650
620
651
621
test ( 'getLineIndentGuide decreasing indent' , ( ) => {
652
622
assertIndentGuides ( [
653
- [ 1 , ' A' ] ,
654
- [ 1 , ' A' ] ,
655
- [ 0 , 'A' ] ,
623
+ [ 1 , 1 , 2 , 1 , ' A' ] ,
624
+ [ 1 , 1 , 2 , 1 , ' A' ] ,
625
+ [ 0 , 3 , 3 , 0 , 'A' ] ,
656
626
] ) ;
657
627
} ) ;
658
628
659
629
test ( 'getLineIndentGuide Java' , ( ) => {
660
630
assertIndentGuides ( [
661
- /* 1*/ [ 0 , 'class A {' ] ,
662
- /* 2*/ [ 1 , ' void foo() {' ] ,
663
- /* 3*/ [ 1 , ' console.log(1);' ] ,
664
- /* 4*/ [ 1 , ' console.log(2);' ] ,
665
- /* 5*/ [ 1 , ' }' ] ,
666
- /* 6*/ [ 1 , '' ] ,
667
- /* 7*/ [ 1 , ' void bar() {' ] ,
668
- /* 8*/ [ 1 , ' console.log(3);' ] ,
669
- /* 9*/ [ 1 , ' }' ] ,
670
- /*10*/ [ 0 , '}' ] ,
671
- /*11*/ [ 0 , 'interface B {' ] ,
672
- /*12*/ [ 1 , ' void bar();' ] ,
673
- /*13*/ [ 0 , '}' ] ,
631
+ /* 1*/ [ 0 , 1 , 1 , 0 , 'class A {' ] ,
632
+ /* 2*/ [ 1 , 2 , 9 , 1 , ' void foo() {' ] ,
633
+ /* 3*/ [ 1 , 2 , 9 , 1 , ' console.log(1);' ] ,
634
+ /* 4*/ [ 1 , 2 , 9 , 1 , ' console.log(2);' ] ,
635
+ /* 5*/ [ 1 , 2 , 9 , 1 , ' }' ] ,
636
+ /* 6*/ [ 1 , 2 , 9 , 1 , '' ] ,
637
+ /* 7*/ [ 1 , 2 , 9 , 1 , ' void bar() {' ] ,
638
+ /* 8*/ [ 1 , 2 , 9 , 1 , ' console.log(3);' ] ,
639
+ /* 9*/ [ 1 , 2 , 9 , 1 , ' }' ] ,
640
+ /*10*/ [ 0 , 10 , 10 , 0 , '}' ] ,
641
+ /*11*/ [ 0 , 11 , 11 , 0 , 'interface B {' ] ,
642
+ /*12*/ [ 1 , 12 , 12 , 1 , ' void bar();' ] ,
643
+ /*13*/ [ 0 , 13 , 13 , 0 , '}' ] ,
674
644
] ) ;
675
645
} ) ;
676
646
677
647
test ( 'getLineIndentGuide Javadoc' , ( ) => {
678
648
assertIndentGuides ( [
679
- [ 0 , '/**' ] ,
680
- [ 1 , ' * Comment' ] ,
681
- [ 1 , ' */' ] ,
682
- [ 0 , 'class A {' ] ,
683
- [ 1 , ' void foo() {' ] ,
684
- [ 1 , ' }' ] ,
685
- [ 0 , '}' ] ,
649
+ [ 0 , 1 , 1 , 0 , '/**' ] ,
650
+ [ 1 , 2 , 3 , 1 , ' * Comment' ] ,
651
+ [ 1 , 2 , 3 , 1 , ' */' ] ,
652
+ [ 0 , 4 , 4 , 0 , 'class A {' ] ,
653
+ [ 1 , 5 , 6 , 1 , ' void foo() {' ] ,
654
+ [ 1 , 5 , 6 , 1 , ' }' ] ,
655
+ [ 0 , 7 , 7 , 0 , '}' ] ,
686
656
] ) ;
687
657
} ) ;
688
658
689
659
test ( 'getLineIndentGuide Whitespace' , ( ) => {
690
660
assertIndentGuides ( [
691
- [ 0 , 'class A {' ] ,
692
- [ 1 , '' ] ,
693
- [ 1 , ' void foo() {' ] ,
694
- [ 1 , ' ' ] ,
695
- [ 2 , ' return 1;' ] ,
696
- [ 1 , ' }' ] ,
697
- [ 1 , ' ' ] ,
698
- [ 0 , '}' ] ,
661
+ [ 0 , 1 , 1 , 0 , 'class A {' ] ,
662
+ [ 1 , 2 , 7 , 1 , '' ] ,
663
+ [ 1 , 2 , 7 , 1 , ' void foo() {' ] ,
664
+ [ 1 , 2 , 7 , 1 , ' ' ] ,
665
+ [ 2 , 5 , 5 , 2 , ' return 1;' ] ,
666
+ [ 1 , 2 , 7 , 1 , ' }' ] ,
667
+ [ 1 , 2 , 7 , 1 , ' ' ] ,
668
+ [ 0 , 8 , 8 , 0 , '}' ]
699
669
] ) ;
700
670
} ) ;
701
671
702
672
test ( 'getLineIndentGuide Tabs' , ( ) => {
703
673
assertIndentGuides ( [
704
- [ 0 , 'class A {' ] ,
705
- [ 1 , '\t\t' ] ,
706
- [ 1 , '\tvoid foo() {' ] ,
707
- [ 2 , '\t \t//hello' ] ,
708
- [ 2 , '\t return 2;' ] ,
709
- [ 1 , ' \t}' ] ,
710
- [ 1 , ' ' ] ,
711
- [ 0 , '}' ] ,
674
+ [ 0 , 1 , 1 , 0 , 'class A {' ] ,
675
+ [ 1 , 2 , 7 , 1 , '\t\t' ] ,
676
+ [ 1 , 2 , 7 , 1 , '\tvoid foo() {' ] ,
677
+ [ 2 , 4 , 5 , 2 , '\t \t//hello' ] ,
678
+ [ 2 , 4 , 5 , 2 , '\t return 2;' ] ,
679
+ [ 1 , 2 , 7 , 1 , ' \t}' ] ,
680
+ [ 1 , 2 , 7 , 1 , ' ' ] ,
681
+ [ 0 , 8 , 8 , 0 , '}' ]
712
682
] ) ;
713
683
} ) ;
714
684
715
685
test ( 'getLineIndentGuide checker.ts' , ( ) => {
716
686
assertIndentGuides ( [
717
- /* 1*/ [ 0 , '/// <reference path="binder.ts"/>' ] ,
718
- /* 2*/ [ 0 , '' ] ,
719
- /* 3*/ [ 0 , '/* @internal */' ] ,
720
- /* 4*/ [ 0 , 'namespace ts {' ] ,
721
- /* 5*/ [ 1 , ' let nextSymbolId = 1;' ] ,
722
- /* 6*/ [ 1 , ' let nextNodeId = 1;' ] ,
723
- /* 7*/ [ 1 , ' let nextMergeId = 1;' ] ,
724
- /* 8*/ [ 1 , ' let nextFlowId = 1;' ] ,
725
- /* 9*/ [ 1 , '' ] ,
726
- /*10*/ [ 1 , ' export function getNodeId(node: Node): number {' ] ,
727
- /*11*/ [ 2 , ' if (!node.id) {' ] ,
728
- /*12*/ [ 3 , ' node.id = nextNodeId;' ] ,
729
- /*13*/ [ 3 , ' nextNodeId++;' ] ,
730
- /*14*/ [ 2 , ' }' ] ,
731
- /*15*/ [ 2 , ' return node.id;' ] ,
732
- /*16*/ [ 1 , ' }' ] ,
733
- /*17*/ [ 0 , '}' ] ,
687
+ /* 1*/ [ 0 , 1 , 1 , 0 , '/// <reference path="binder.ts"/>' ] ,
688
+ /* 2*/ [ 0 , 2 , 2 , 0 , '' ] ,
689
+ /* 3*/ [ 0 , 3 , 3 , 0 , '/* @internal */' ] ,
690
+ /* 4*/ [ 0 , 4 , 4 , 0 , 'namespace ts {' ] ,
691
+ /* 5*/ [ 1 , 5 , 16 , 1 , ' let nextSymbolId = 1;' ] ,
692
+ /* 6*/ [ 1 , 5 , 16 , 1 , ' let nextNodeId = 1;' ] ,
693
+ /* 7*/ [ 1 , 5 , 16 , 1 , ' let nextMergeId = 1;' ] ,
694
+ /* 8*/ [ 1 , 5 , 16 , 1 , ' let nextFlowId = 1;' ] ,
695
+ /* 9*/ [ 1 , 5 , 16 , 1 , '' ] ,
696
+ /*10*/ [ 1 , 5 , 16 , 1 , ' export function getNodeId(node: Node): number {' ] ,
697
+ /*11*/ [ 2 , 11 , 15 , 2 , ' if (!node.id) {' ] ,
698
+ /*12*/ [ 3 , 12 , 13 , 3 , ' node.id = nextNodeId;' ] ,
699
+ /*13*/ [ 3 , 12 , 13 , 3 , ' nextNodeId++;' ] ,
700
+ /*14*/ [ 2 , 11 , 15 , 2 , ' }' ] ,
701
+ /*15*/ [ 2 , 11 , 15 , 2 , ' return node.id;' ] ,
702
+ /*16*/ [ 1 , 5 , 16 , 1 , ' }' ] ,
703
+ /*17*/ [ 0 , 17 , 17 , 0 , '}' ]
734
704
] ) ;
735
705
} ) ;
736
706
737
707
test ( 'issue #8425 - Missing indentation lines for first level indentation' , ( ) => {
738
708
assertIndentGuides ( [
739
- [ 1 , '\tindent1' ] ,
740
- [ 2 , '\t\tindent2' ] ,
741
- [ 2 , '\t\tindent2' ] ,
742
- [ 1 , '\tindent1' ] ,
709
+ [ 1 , 1 , 4 , 1 , '\tindent1' ] ,
710
+ [ 2 , 2 , 3 , 2 , '\t\tindent2' ] ,
711
+ [ 2 , 2 , 3 , 2 , '\t\tindent2' ] ,
712
+ [ 1 , 1 , 4 , 1 , '\tindent1' ]
743
713
] ) ;
744
714
} ) ;
745
715
746
716
test ( 'issue #8952 - Indentation guide lines going through text on .yml file' , ( ) => {
747
717
assertIndentGuides ( [
748
- [ 0 , 'properties:' ] ,
749
- [ 1 , ' emailAddress:' ] ,
750
- [ 2 , ' - bla' ] ,
751
- [ 2 , ' - length:' ] ,
752
- [ 3 , ' max: 255' ] ,
753
- [ 0 , 'getters:' ] ,
718
+ [ 0 , 1 , 1 , 0 , 'properties:' ] ,
719
+ [ 1 , 2 , 5 , 1 , ' emailAddress:' ] ,
720
+ [ 2 , 3 , 5 , 2 , ' - bla' ] ,
721
+ [ 2 , 3 , 5 , 2 , ' - length:' ] ,
722
+ [ 3 , 5 , 5 , 3 , ' max: 255' ] ,
723
+ [ 0 , 6 , 6 , 0 , 'getters:' ]
754
724
] ) ;
755
725
} ) ;
756
726
757
727
test ( 'issue #11892 - Indent guides look funny' , ( ) => {
758
728
assertIndentGuides ( [
759
- [ 0 , 'function test(base) {' ] ,
760
- [ 1 , '\tswitch (base) {' ] ,
761
- [ 2 , '\t\tcase 1:' ] ,
762
- [ 3 , '\t\t\treturn 1;' ] ,
763
- [ 2 , '\t\tcase 2:' ] ,
764
- [ 3 , '\t\t\treturn 2;' ] ,
765
- [ 1 , '\t}' ] ,
766
- [ 0 , '}' ] ,
729
+ [ 0 , 1 , 1 , 0 , 'function test(base) {' ] ,
730
+ [ 1 , 2 , 7 , 1 , '\tswitch (base) {' ] ,
731
+ [ 2 , 3 , 6 , 2 , '\t\tcase 1:' ] ,
732
+ [ 3 , 4 , 4 , 3 , '\t\t\treturn 1;' ] ,
733
+ [ 2 , 3 , 6 , 2 , '\t\tcase 2:' ] ,
734
+ [ 3 , 6 , 6 , 3 , '\t\t\treturn 2;' ] ,
735
+ [ 1 , 2 , 7 , 1 , '\t}' ] ,
736
+ [ 0 , 8 , 8 , 0 , '}' ]
767
737
] ) ;
768
738
} ) ;
769
739
770
740
test ( 'issue #12398 - Problem in indent guidelines' , ( ) => {
771
741
assertIndentGuides ( [
772
- [ 2 , '\t\t.bla' ] ,
773
- [ 3 , '\t\t\tlabel(for)' ] ,
774
- [ 0 , 'include script' ] ,
742
+ [ 2 , 1 , 2 , 2 , '\t\t.bla' ] ,
743
+ [ 3 , 2 , 2 , 3 , '\t\t\tlabel(for)' ] ,
744
+ [ 0 , 3 , 3 , 0 , 'include script' ]
775
745
] ) ;
776
746
} ) ;
777
747
0 commit comments