From b4bb37ad1c9d4d0c52afd88ed2bf82abbf3337f0 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 17 Apr 2020 10:31:05 +0200 Subject: [PATCH] Don't let trivia content before make a member definition multiline. Fixes #757 --- src/Fantomas.Tests/ClassTests.fs | 2 -- src/Fantomas.Tests/TypeDeclarationTests.fs | 20 +++++++++++++++++++- src/Fantomas/CodePrinter.fs | 12 ++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/Fantomas.Tests/ClassTests.fs b/src/Fantomas.Tests/ClassTests.fs index 6f07b2be41..01983c5446 100644 --- a/src/Fantomas.Tests/ClassTests.fs +++ b/src/Fantomas.Tests/ClassTests.fs @@ -109,7 +109,6 @@ type Shape2D(x0: float, y0: float) = and set yval = y <- yval abstract Area: float - abstract Perimeter: float abstract Name: string @@ -118,7 +117,6 @@ type Shape2D(x0: float, y0: float) = y <- y + dy abstract Rotate: float -> unit - default this.Rotate(angle) = rotAngle <- rotAngle + angle """ diff --git a/src/Fantomas.Tests/TypeDeclarationTests.fs b/src/Fantomas.Tests/TypeDeclarationTests.fs index a8b3ab63f6..87356774d8 100644 --- a/src/Fantomas.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Tests/TypeDeclarationTests.fs @@ -95,7 +95,6 @@ type Test() = member this.Function1<'a>(x, y) = printfn "%A, %A" x y abstract AbstractMethod<'a, 'b> : 'a * 'b -> unit - override this.AbstractMethod<'a, 'b>(x: 'a, y: 'b) = printfn "%A, %A" x y """ @@ -1033,4 +1032,23 @@ type FormattingSpecs() = [] let ``false is false`` () = test <@ false = false @> +""" + +[] +let ``line comment above single line abstract slot should not make it multiline, 757`` () = + formatSourceString false """[] +type Graph2dOptions = + abstract zoomMin: float option with get, set + // abstract moment: MomentConstructor option with get, set + abstract maxHeight: HeightWidthType option with get, set + abstract zIndex: float option with get, set +""" config + |> prepend newline + |> should equal """ +[] +type Graph2dOptions = + abstract zoomMin: float option with get, set + // abstract moment: MomentConstructor option with get, set + abstract maxHeight: HeightWidthType option with get, set + abstract zIndex: float option with get, set """ \ No newline at end of file diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 9de46de25f..9baca72a2b 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -2330,10 +2330,14 @@ and genMemberDefnList astContext node = | m::rest -> let attrs = getRangesFromAttributesFromSynMemberDefinition m - sepNlnConsideringTriviaContentBeforeWithAttributes m.Range attrs +> - (expressionFitsOnRestOfLine - (genMemberDefn astContext m) - (sepNlnBeforeMultilineConstruct m.Range attrs +> genMemberDefn astContext m +> onlyIf (List.isNotEmpty rest) sepNln)) + + sepNlnConsideringTriviaContentBeforeWithAttributes m.Range attrs + +> enterNode m.Range + +> (expressionFitsOnRestOfLine + (genMemberDefn astContext m) + (sepNlnBeforeMultilineConstruct m.Range attrs + +> genMemberDefn astContext m + +> onlyIf (List.isNotEmpty rest) sepNln)) +> genMemberDefnList astContext rest