Changed logic for break/continue search in switch statements and loops.

Now if a labeled break in a switch refers to its original switch statement, we also highlight the 'switch' keyword.

Also added tests for loop/break/continue.
This commit is contained in:
Daniel Rosenwasser
2014-09-05 10:59:20 -07:00
parent 69803d4d3c
commit 90dd327635
9 changed files with 561 additions and 37 deletions

View File

@@ -0,0 +1,77 @@
/// <reference path='fourslash.ts' />
////var arr = [1, 2, 3, 4];
////label1: [|for|] (var n in arr) {
//// [|break|];
//// [|continue|];
//// [|br/**/eak|] label1;
//// [|continue|] label1;
////
//// label2: for (var i = 0; i < arr[n]; i++) {
//// [|break|] label1;
//// [|continue|] label1;
////
//// break;
//// continue;
//// break label2;
//// continue label2;
////
//// function foo() {
//// label3: while (true) {
//// break;
//// continue;
//// break label3;
//// continue label3;
////
//// // these cross function boundaries
//// break label1;
//// continue label1;
//// break label2;
//// continue label2;
////
//// label4: do {
//// break;
//// continue;
//// break label4;
//// continue label4;
////
//// break label3;
//// continue label3;
////
//// switch (10) {
//// case 1:
//// case 2:
//// break;
//// break label4;
//// default:
//// continue;
//// }
////
//// // these cross function boundaries
//// break label1;
//// continue label1;
//// break label2;
//// continue label2;
//// () => { break; }
//// } while (true)
//// }
//// }
//// }
////}
////
////label5: while (true) break label5;
////
////label7: while (true) continue label5;
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
});
goTo.marker();
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});

View File

@@ -0,0 +1,77 @@
/// <reference path='fourslash.ts' />
////var arr = [1, 2, 3, 4];
////label1: for (var n in arr) {
//// break;
//// continue;
//// break label1;
//// continue label1;
////
//// label2: [|f/**/or|] (var i = 0; i < arr[n]; i++) {
//// break label1;
//// continue label1;
////
//// [|break|];
//// [|continue|];
//// [|break|] label2;
//// [|continue|] label2;
////
//// function foo() {
//// label3: while (true) {
//// break;
//// continue;
//// break label3;
//// continue label3;
////
//// // these cross function boundaries
//// break label1;
//// continue label1;
//// break label2;
//// continue label2;
////
//// label4: do {
//// break;
//// continue;
//// break label4;
//// continue label4;
////
//// break label3;
//// continue label3;
////
//// switch (10) {
//// case 1:
//// case 2:
//// break;
//// break label4;
//// default:
//// continue;
//// }
////
//// // these cross function boundaries
//// break label1;
//// continue label1;
//// break label2;
//// continue label2;
//// () => { break;
//// } while (true)
//// }
//// }
//// }
////}
////
////label5: while (true) break label5;
////
////label7: while (true) continue label5;
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
});
goTo.marker();
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});

View File

@@ -0,0 +1,77 @@
/// <reference path='fourslash.ts' />
////var arr = [1, 2, 3, 4];
////label1: for (var n in arr) {
//// break;
//// continue;
//// break label1;
//// continue label1;
////
//// label2: for (var i = 0; i < arr[n]; i++) {
//// break label1;
//// continue label1;
////
//// break;
//// continue;
//// break label2;
//// continue label2;
////
//// function foo() {
//// label3: [|w/**/hile|] (true) {
//// [|break|];
//// [|continue|];
//// [|break|] label3;
//// [|continue|] label3;
////
//// // these cross function boundaries
//// break label1;
//// continue label1;
//// break label2;
//// continue label2;
////
//// label4: do {
//// break;
//// continue;
//// break label4;
//// continue label4;
////
//// [|break|] label3;
//// [|continue|] label3;
////
//// switch (10) {
//// case 1:
//// case 2:
//// break;
//// break label4;
//// default:
//// continue;
//// }
////
//// // these cross function boundaries
//// break label1;
//// continue label1;
//// break label2;
//// continue label2;
//// () => { break; }
//// } while (true)
//// }
//// }
//// }
////}
////
////label5: while (true) break label5;
////
////label7: while (true) continue label5;
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
});
goTo.marker();
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});

View File

@@ -0,0 +1,77 @@
/// <reference path='fourslash.ts' />
////var arr = [1, 2, 3, 4];
////label1: for (var n in arr) {
//// break;
//// continue;
//// break label1;
//// continue label1;
////
//// label2: for (var i = 0; i < arr[n]; i++) {
//// break label1;
//// continue label1;
////
//// break;
//// continue;
//// break label2;
//// continue label2;
////
//// function foo() {
//// label3: while (true) {
//// break;
//// continue;
//// break label3;
//// continue label3;
////
//// // these cross function boundaries
//// break label1;
//// continue label1;
//// break label2;
//// continue label2;
////
//// label4: [|do|] {
//// [|break|];
//// [|continue|];
//// [|break|] label4;
//// [|continue|] label4;
////
//// break label3;
//// continue label3;
////
//// switch (10) {
//// case 1:
//// case 2:
//// break;
//// [|break|] label4;
//// default:
//// [|continue|];
//// }
////
//// // these cross function boundaries
//// break label1;
//// continue label1;
//// break label2;
//// continue label2;
//// () => { break; }
//// } [|wh/**/ile|] (true)
//// }
//// }
//// }
////}
////
////label5: while (true) break label5;
////
////label7: while (true) continue label5;
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
});
goTo.marker();
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});

View File

@@ -0,0 +1,77 @@
/// <reference path='fourslash.ts' />
////var arr = [1, 2, 3, 4];
////label1: for (var n in arr) {
//// break;
//// continue;
//// break label1;
//// continue label1;
////
//// label2: for (var i = 0; i < arr[n]; i++) {
//// break label1;
//// continue label1;
////
//// break;
//// continue;
//// break label2;
//// continue label2;
////
//// function foo() {
//// label3: while (true) {
//// break;
//// continue;
//// break label3;
//// continue label3;
////
//// // these cross function boundaries
//// break label1;
//// continue label1;
//// break label2;
//// continue label2;
////
//// label4: do {
//// break;
//// continue;
//// break label4;
//// continue label4;
////
//// break label3;
//// continue label3;
////
//// switch (10) {
//// case 1:
//// case 2:
//// break;
//// break label4;
//// default:
//// continue;
//// }
////
//// // these cross function boundaries
//// break label1;
//// continue label1;
//// break label2;
//// continue label2;
//// () => { break; }
//// } while (true)
//// }
//// }
//// }
////}
////
////label5: [|while|] (true) [|br/**/eak|] label5;
////
////label7: while (true) continue label5;
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
});
goTo.marker();
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});

View File

@@ -0,0 +1,70 @@
/// <reference path='fourslash.ts' />
////var arr = [1, 2, 3, 4];
////label1: for (var n in arr) {
//// break;
//// continue;
//// break label1;
//// continue label1;
////
//// label2: for (var i = 0; i < arr[n]; i++) {
//// break label1;
//// continue label1;
////
//// break;
//// continue;
//// break label2;
//// continue label2;
////
//// function foo() {
//// label3: while (true) {
//// break;
//// continue;
//// break label3;
//// continue label3;
////
//// // these cross function boundaries
//// br/*1*/eak label1;
//// cont/*2*/inue label1;
//// bre/*3*/ak label2;
//// c/*4*/ontinue label2;
////
//// label4: do {
//// break;
//// continue;
//// break label4;
//// continue label4;
////
//// break label3;
//// continue label3;
////
//// switch (10) {
//// case 1:
//// case 2:
//// break;
//// break label4;
//// default:
//// continue;
//// }
////
//// // these cross function boundaries
//// br/*5*/eak label1;
//// co/*6*/ntinue label1;
//// br/*7*/eak label2;
//// con/*8*/tinue label2;
//// () => { b/*9*/reak; }
//// } while (true)
//// }
//// }
//// }
////}
////
////label5: while (true) break label5;
////
////label7: while (true) co/*10*/ntinue label5;
test.markers().forEach(m => {
goTo.position(m.position);
verify.occurrencesAtPositionCount(0);
});

View File

@@ -10,7 +10,7 @@
//// [|cas/*3*/e|] 2:
//// [|b/*4*/reak|];
//// [|defaul/*5*/t|]:
//// break foo;
//// [|break|] foo;
//// }
//// case 0xBEEF:
//// default:
@@ -19,9 +19,18 @@
////}
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
});
for (var i = 1; i <= test.markers().length; i++) {
goTo.marker("" + i);
verify.occurrencesAtPositionCount(5);
verify.occurrencesAtPositionCount(6);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);

View File

@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
////foo: [|switch|] (1) {
//// [|case|] 1:
//// [|case|] 2:
//// [|break|];
//// [|case|] 3:
//// switch (2) {
//// case 1:
//// [|break|] foo;
//// continue; // invalid
//// default:
//// break;
//// }
//// [|default|]:
//// [|break|];
////}
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
});