Add outlining spans for case clauses (#37374)

* Add outlining spans for case clauses

* Update old test

* Update other test

* Update yet another of the same test
This commit is contained in:
Andrew Branch
2020-03-13 09:52:27 -08:00
committed by GitHub
parent ba39113ab9
commit db44231e38
5 changed files with 48 additions and 4 deletions

View File

@@ -200,6 +200,9 @@ namespace ts.OutliningElementsCollector {
case SyntaxKind.EnumDeclaration:
case SyntaxKind.CaseBlock:
return spanForNode(n);
case SyntaxKind.CaseClause:
case SyntaxKind.DefaultClause:
return spanForNodeArray((n as CaseClause | DefaultClause).statements);
case SyntaxKind.ObjectLiteralExpression:
return spanForObjectOrArrayLiteral(n);
case SyntaxKind.ArrayLiteralExpression:
@@ -256,6 +259,10 @@ namespace ts.OutliningElementsCollector {
const closeToken = findChildOfKind(n, close, sourceFile);
return openToken && closeToken && spanBetweenTokens(openToken, closeToken, hintSpanNode, sourceFile, autoCollapse, useFullStart);
}
function spanForNodeArray(nodeArray: NodeArray<Node>): OutliningSpan | undefined {
return nodeArray.length ? createOutliningSpan(createTextSpanFromRange(nodeArray), OutliningSpanKind.Code) : undefined;
}
}
function functionSpan(node: FunctionLike, body: Block, sourceFile: SourceFile): OutliningSpan | undefined {

View File

@@ -32,7 +32,7 @@
//// }|]
//// }|])
////switch(1)[| {
//// case 1: break;
//// case 1:[| break;|]
////}|]
////
////var array =[| [

View File

@@ -0,0 +1,37 @@
/// <reference path="fourslash.ts" />
////switch (undefined)[| {
//// case 0:[|
//// console.log(1)
//// console.log(2)
//// break;
//// console.log(3);|]
//// case 1:[|
//// break;|]
//// case 2:[|
//// break;
//// console.log(3);|]
//// case 3:[|
//// console.log(4);|]
////
//// case 4:
//// case 5:
//// case 6:[|
////
////
//// console.log(5);|]
////
//// case 7:[| console.log(6);|]
////
//// case 8:[| [|{
//// console.log(8);
//// break;
//// }|]
//// console.log(8);|]
////
//// default:[|
//// console.log(7);
//// console.log(8);|]
////}|]
verify.outliningSpansInCurrentFile(test.ranges(), "code");

View File

@@ -1,4 +1,4 @@
/// <reference path="fourslash.ts"/>
/// <reference path="../fourslash.ts"/>
////// interface
////interface IFoo[| {
@@ -26,7 +26,7 @@
//// }|]
////}|]
////switch(1)[| {
//// case 1: break;
//// case 1:[| break;|]
////}|]
////
////var array =[| [

View File

@@ -26,7 +26,7 @@
//// }|]
////}|]
////switch(1)[| {
//// case 1: break;
//// case 1:[| break;|]
////}|]
////
////var array =[| [