diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index f818123abdcb4..6830a6e0b407e 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -276,9 +276,7 @@ namespace ts.OutliningElementsCollector { } function functionSpan(node: FunctionLike, body: Block, sourceFile: SourceFile): OutliningSpan | undefined { - const openToken = isNodeArrayMultiLine(node.parameters, sourceFile) - ? findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile) - : findChildOfKind(body, SyntaxKind.OpenBraceToken, sourceFile); + const openToken = tryGetFunctionOpenToken(node, body, sourceFile); const closeToken = findChildOfKind(body, SyntaxKind.CloseBraceToken, sourceFile); return openToken && closeToken && spanBetweenTokens(openToken, closeToken, node, sourceFile, /*autoCollapse*/ node.kind !== SyntaxKind.ArrowFunction); } @@ -291,4 +289,14 @@ namespace ts.OutliningElementsCollector { function createOutliningSpan(textSpan: TextSpan, kind: OutliningSpanKind, hintSpan: TextSpan = textSpan, autoCollapse = false, bannerText = "..."): OutliningSpan { return { textSpan, kind, hintSpan, bannerText, autoCollapse }; } + + function tryGetFunctionOpenToken(node: FunctionLike, body: Block, sourceFile: SourceFile): Node | undefined { + if (isNodeArrayMultiLine(node.parameters, sourceFile)) { + const openParenToken = findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile); + if (openParenToken) { + return openParenToken; + } + } + return findChildOfKind(body, SyntaxKind.OpenBraceToken, sourceFile); + } } diff --git a/tests/cases/fourslash/outliningSpansForFunction.ts b/tests/cases/fourslash/outliningSpansForFunction.ts index acc00eedbee3a..f46886b73068d 100644 --- a/tests/cases/fourslash/outliningSpansForFunction.ts +++ b/tests/cases/fourslash/outliningSpansForFunction.ts @@ -1,14 +1,84 @@ /// -////function f(x: number, y: number)[| { -//// return x + y; +////[|( +//// a: number, +//// b: number +////) => { +//// return a + b; +////}|] +///// +////(a: number, b: number) => [|{ +//// return a + b; +////}|] +//// +////const f1 = function[| ( +//// a: number +//// b: number +////) { +//// return a + b; +////}|] +//// +////const f2 = function (a: number, b: number)[| { +//// return a + b; ////}|] //// -////function g[|( -//// x: number, -//// y: number, -////): number { -//// return x + y; +////function f3[| ( +//// a: number +//// b: number +////) { +//// return a + b; ////}|] +//// +////function f4(a: number, b: number)[| { +//// return a + b; +////}|] +//// +////class Foo[| { +//// constructor[|( +//// a: number, +//// b: number +//// ) { +//// this.a = a; +//// this.b = b; +//// }|] +//// +//// m1[|( +//// a: number, +//// b: number +//// ) { +//// return a + b; +//// }|] +//// +//// m1(a: number, b: number)[| { +//// return a + b; +//// }|] +////}|] +//// +////declare function foo(props: any): void; +////foo( +//// a =>[| { +//// +//// }|] +////) +//// +////foo( +//// (a) =>[| { +//// +//// }|] +////) +//// +////foo( +//// (a, b, c) =>[| { +//// +//// }|] +////) +//// +////foo([| +//// (a, +//// b, +//// c) => { +//// +//// }|] +////) verify.outliningSpansInCurrentFile(test.ranges());