From 2b703d254a72d78740d65dc1c6743ae00245e404 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Mon, 18 May 2020 15:22:03 +0300 Subject: [PATCH] fix(33233): add outlining for comments before property access expression --- src/services/outliningElementsCollector.ts | 4 ++++ .../fourslash/getOutliningForBlockComments.ts | 20 +++++++++++++++++++ .../getOutliningForSingleLineComments.ts | 12 +++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 7f3028c2c6f62..f818123abdcb4 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -42,6 +42,10 @@ namespace ts.OutliningElementsCollector { addOutliningForLeadingCommentsForNode(n.parent.parent.parent, sourceFile, cancellationToken, out); } + if (isFunctionLike(n) && isBinaryExpression(n.parent) && isPropertyAccessExpression(n.parent.left)) { + addOutliningForLeadingCommentsForNode(n.parent.left, sourceFile, cancellationToken, out); + } + const span = getOutliningSpanForNode(n, sourceFile); if (span) out.push(span); diff --git a/tests/cases/fourslash/getOutliningForBlockComments.ts b/tests/cases/fourslash/getOutliningForBlockComments.ts index cc0bbc3c31076..567806877ba1d 100644 --- a/tests/cases/fourslash/getOutliningForBlockComments.ts +++ b/tests/cases/fourslash/getOutliningForBlockComments.ts @@ -110,6 +110,26 @@ //// const sum2 = (y, z) =>[| { //// return y + z; //// }|]; +//// +////function Foo()[| { +//// [|/** +//// * Description +//// * +//// * @param {string} param +//// * @returns +//// */|] +//// this.method = function (param)[| { +//// }|] +//// +//// [|/** +//// * Description +//// * +//// * @param {string} param +//// * @returns +//// */|] +//// function method(param)[| { +//// }|] +////}|] verify.outliningSpansInCurrentFile(test.ranges()); diff --git a/tests/cases/fourslash/getOutliningForSingleLineComments.ts b/tests/cases/fourslash/getOutliningForSingleLineComments.ts index 903b1c55494ce..9ada3fca44637 100644 --- a/tests/cases/fourslash/getOutliningForSingleLineComments.ts +++ b/tests/cases/fourslash/getOutliningForSingleLineComments.ts @@ -72,6 +72,18 @@ ////// One single line comment should not be collapsed ////class WithOneSingleLineComment[| { ////}|] +//// +////function Foo()[| { +//// [|// comment 1 +//// // comment 2|] +//// this.method = function (param)[| { +//// }|] +//// +//// [|// comment 1 +//// // comment 2|] +//// function method(param)[| { +//// }|] +////}|] verify.outliningSpansInCurrentFile(test.ranges());