Merge pull request #39109 from Kingwl/lambda_span

Add outlining spans for call expression or arrow body
This commit is contained in:
Daniel Rosenwasser
2020-06-29 23:33:04 -07:00
committed by GitHub
6 changed files with 143 additions and 85 deletions

View File

@@ -227,6 +227,31 @@ namespace ts.OutliningElementsCollector {
return spanForTemplateLiteral(<TemplateExpression | NoSubstitutionTemplateLiteral>n);
case SyntaxKind.ArrayBindingPattern:
return spanForNode(n, /*autoCollapse*/ false, /*useFullStart*/ !isBindingElement(n.parent), SyntaxKind.OpenBracketToken);
case SyntaxKind.ArrowFunction:
return spanForArrowFunction(<ArrowFunction>n);
case SyntaxKind.CallExpression:
return spanForCallExpression(<CallExpression>n);
}
function spanForCallExpression(node: CallExpression): OutliningSpan | undefined {
if (!node.arguments.length) {
return undefined;
}
const openToken = findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile);
const closeToken = findChildOfKind(node, SyntaxKind.CloseParenToken, sourceFile);
if (!openToken || !closeToken || positionsAreOnSameLine(openToken.pos, closeToken.pos, sourceFile)) {
return undefined;
}
return spanBetweenTokens(openToken, closeToken, node, sourceFile, /*autoCollapse*/ false, /*useFullStart*/ true);
}
function spanForArrowFunction(node: ArrowFunction): OutliningSpan | undefined {
if (isBlock(node.body) || positionsAreOnSameLine(node.body.getFullStart(), node.body.getEnd(), sourceFile)) {
return undefined;
}
const textSpan = createTextSpanFromBounds(node.body.getFullStart(), node.body.getEnd());
return createOutliningSpan(textSpan, OutliningSpanKind.Code, createTextSpanFromNode(node));
}
function spanForJSXElement(node: JsxElement): OutliningSpan | undefined {

View File

@@ -106,14 +106,14 @@
////function f(x: number[], y: number[])[| {
//// return 3;
////}|]
////f(
////f[|(
////// single line array literal span won't render in VS
//// [|[0]|],
//// [|[
//// 1,
//// 2
//// ]|]
////);
////)|];
verify.outliningSpansInCurrentFile(test.ranges(), "code");

View File

@@ -4,113 +4,113 @@
////declare var router: any;
////router
//// .get("/", async(ctx) =>[|{
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// .get("/", async(ctx) =>[|{
//// }|])|]
//// .get[|("/", async(ctx) =>[|{
//// ctx.body = "base";
//// }|])
//// .post("/a", async(ctx) =>[|{
//// }|])|]
//// .post[|("/a", async(ctx) =>[|{
//// //a
//// }|])
//// }|])|]
verify.outliningSpansInCurrentFile(test.ranges());

View File

@@ -0,0 +1,18 @@
/// <reference path="fourslash.ts"/>
//// console.log(123, 456)l;
//// console.log(
//// );
//// console.log[|(
//// 123, 456
//// )|];
//// console.log[|(
//// 123,
//// 456
//// )|];
//// () =>[| console.log[|(
//// 123,
//// 456
//// )|]|];
verify.outliningSpansInCurrentFile(test.ranges());

View File

@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts"/>
//// () => 42;
//// () => ( 42 );
//// () =>[| {
//// 42
//// }|];
//// () =>[| (
//// 42
//// )|];
//// () =>[| "foo" +
//// "bar" +
//// "baz"|];
verify.outliningSpansInCurrentFile(test.ranges());

View File

@@ -5,9 +5,9 @@
//// b: number
////) => {
//// return a + b;
////}|]
/////
////(a: number, b: number) => [|{
////}|];
////
////(a: number, b: number) =>[| {
//// return a + b;
////}|]
////
@@ -55,30 +55,30 @@
////}|]
////
////declare function foo(props: any): void;
////foo(
////foo[|(
//// a =>[| {
////
//// }|]
////)
////)|]
////
////foo(
////foo[|(
//// (a) =>[| {
////
//// }|]
////)
////)|]
////
////foo(
////foo[|(
//// (a, b, c) =>[| {
////
//// }|]
////)
////)|]
////
////foo([|
////foo[|([|
//// (a,
//// b,
//// c) => {
////
//// }|]
////)
////)|]
verify.outliningSpansInCurrentFile(test.ranges());