diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 90c53d47561..9d590ffef61 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -21,7 +21,17 @@ namespace ts.OutliningElementsCollector { if (span) out.push(span); depthRemaining--; - n.forEachChild(walk); + if (isIfStatement(n) && isIfStatement(n.elseStatement)) { + // Consider an 'else if' to be on the same depth as the 'if'. + walk(n.expression); + walk(n.thenStatement); + depthRemaining++; + walk(n.elseStatement); + depthRemaining--; + } + else { + n.forEachChild(walk); + } depthRemaining++; }); } diff --git a/tests/cases/fourslash/getOutliningSpansDepthElseIf.ts b/tests/cases/fourslash/getOutliningSpansDepthElseIf.ts new file mode 100644 index 00000000000..1e349e5b190 --- /dev/null +++ b/tests/cases/fourslash/getOutliningSpansDepthElseIf.ts @@ -0,0 +1,89 @@ +/// + +// Tests that each 'else if' does not count towards a higher nesting depth. + +////if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else if (1)[| { +//// 1; +////}|] else[| { +//// 1; +////}|] + +verify.outliningSpansInCurrentFile(test.ranges());