mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Merge pull request #39109 from Kingwl/lambda_span
Add outlining spans for call expression or arrow body
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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());
|
||||
|
||||
18
tests/cases/fourslash/outliningSpansForArguments.ts
Normal file
18
tests/cases/fourslash/outliningSpansForArguments.ts
Normal 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());
|
||||
15
tests/cases/fourslash/outliningSpansForArrowFunctionBody.ts
Normal file
15
tests/cases/fourslash/outliningSpansForArrowFunctionBody.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// () => 42;
|
||||
//// () => ( 42 );
|
||||
//// () =>[| {
|
||||
//// 42
|
||||
//// }|];
|
||||
//// () =>[| (
|
||||
//// 42
|
||||
//// )|];
|
||||
//// () =>[| "foo" +
|
||||
//// "bar" +
|
||||
//// "baz"|];
|
||||
|
||||
verify.outliningSpansInCurrentFile(test.ranges());
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user