From 31a1cdd6879b444b4940304c9b9ebade5bd287c6 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Thu, 26 Dec 2019 17:10:59 +0200 Subject: [PATCH] Fixed outlining spans for chained method calls. --- src/services/outliningElementsCollector.ts | 9 +- .../getOutliningSpansDepthChainedCalls.ts | 116 ++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/getOutliningSpansDepthChainedCalls.ts diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index ce0fe7b28be2c..7b97161aabe8f 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -45,7 +45,14 @@ namespace ts.OutliningElementsCollector { if (span) out.push(span); depthRemaining--; - if (isIfStatement(n) && n.elseStatement && isIfStatement(n.elseStatement)) { + if (isCallExpression(n)) { + depthRemaining++; + visitNonImportNode(n.expression); + depthRemaining--; + n.arguments.forEach(visitNonImportNode); + n.typeArguments?.forEach(visitNonImportNode); + } + else if (isIfStatement(n) && n.elseStatement && isIfStatement(n.elseStatement)) { // Consider an 'else if' to be on the same depth as the 'if'. visitNonImportNode(n.expression); visitNonImportNode(n.thenStatement); diff --git a/tests/cases/fourslash/getOutliningSpansDepthChainedCalls.ts b/tests/cases/fourslash/getOutliningSpansDepthChainedCalls.ts new file mode 100644 index 0000000000000..9fc8c50dd7044 --- /dev/null +++ b/tests/cases/fourslash/getOutliningSpansDepthChainedCalls.ts @@ -0,0 +1,116 @@ +/// + +// Tests that each 'else if' does not count towards a higher nesting depth. + +////declare var router: any; +////router +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) +//// .get("/", async(ctx) =>[|{ +//// ctx.body = "base"; +//// }|]) +//// .post("/a", async(ctx) =>[|{ +//// //a +//// }|]) + +verify.outliningSpansInCurrentFile(test.ranges());