Skip to content

Commit db44231

Browse files
authored
Add outlining spans for case clauses (microsoft#37374)
* Add outlining spans for case clauses * Update old test * Update other test * Update yet another of the same test
1 parent ba39113 commit db44231

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

src/services/outliningElementsCollector.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ namespace ts.OutliningElementsCollector {
200200
case SyntaxKind.EnumDeclaration:
201201
case SyntaxKind.CaseBlock:
202202
return spanForNode(n);
203+
case SyntaxKind.CaseClause:
204+
case SyntaxKind.DefaultClause:
205+
return spanForNodeArray((n as CaseClause | DefaultClause).statements);
203206
case SyntaxKind.ObjectLiteralExpression:
204207
return spanForObjectOrArrayLiteral(n);
205208
case SyntaxKind.ArrayLiteralExpression:
@@ -256,6 +259,10 @@ namespace ts.OutliningElementsCollector {
256259
const closeToken = findChildOfKind(n, close, sourceFile);
257260
return openToken && closeToken && spanBetweenTokens(openToken, closeToken, hintSpanNode, sourceFile, autoCollapse, useFullStart);
258261
}
262+
263+
function spanForNodeArray(nodeArray: NodeArray<Node>): OutliningSpan | undefined {
264+
return nodeArray.length ? createOutliningSpan(createTextSpanFromRange(nodeArray), OutliningSpanKind.Code) : undefined;
265+
}
259266
}
260267

261268
function functionSpan(node: FunctionLike, body: Block, sourceFile: SourceFile): OutliningSpan | undefined {

tests/cases/fourslash/getOutliningSpans.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
//// }|]
3333
//// }|])
3434
////switch(1)[| {
35-
//// case 1: break;
35+
//// case 1:[| break;|]
3636
////}|]
3737
////
3838
////var array =[| [
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////switch (undefined)[| {
4+
//// case 0:[|
5+
//// console.log(1)
6+
//// console.log(2)
7+
//// break;
8+
//// console.log(3);|]
9+
//// case 1:[|
10+
//// break;|]
11+
//// case 2:[|
12+
//// break;
13+
//// console.log(3);|]
14+
//// case 3:[|
15+
//// console.log(4);|]
16+
////
17+
//// case 4:
18+
//// case 5:
19+
//// case 6:[|
20+
////
21+
////
22+
//// console.log(5);|]
23+
////
24+
//// case 7:[| console.log(6);|]
25+
////
26+
//// case 8:[| [|{
27+
//// console.log(8);
28+
//// break;
29+
//// }|]
30+
//// console.log(8);|]
31+
////
32+
//// default:[|
33+
//// console.log(7);
34+
//// console.log(8);|]
35+
////}|]
36+
37+
verify.outliningSpansInCurrentFile(test.ranges(), "code");

tests/cases/fourslash/shims-pp/getOutliningSpans.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="fourslash.ts"/>
1+
/// <reference path="../fourslash.ts"/>
22

33
////// interface
44
////interface IFoo[| {
@@ -26,7 +26,7 @@
2626
//// }|]
2727
////}|]
2828
////switch(1)[| {
29-
//// case 1: break;
29+
//// case 1:[| break;|]
3030
////}|]
3131
////
3232
////var array =[| [

tests/cases/fourslash/shims/getOutliningSpans.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//// }|]
2727
////}|]
2828
////switch(1)[| {
29-
//// case 1: break;
29+
//// case 1:[| break;|]
3030
////}|]
3131
////
3232
////var array =[| [

0 commit comments

Comments
 (0)