Skip to content

Commit

Permalink
Don't let trivia content before make a member definition multiline. F…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Apr 17, 2020
1 parent de781f3 commit b4bb37a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/Fantomas.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ type Shape2D(x0: float, y0: float) =
and set yval = y <- yval
abstract Area: float
abstract Perimeter: float
abstract Name: string
Expand All @@ -118,7 +117,6 @@ type Shape2D(x0: float, y0: float) =
y <- y + dy
abstract Rotate: float -> unit
default this.Rotate(angle) = rotAngle <- rotAngle + angle
"""

Expand Down
20 changes: 19 additions & 1 deletion src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand Down Expand Up @@ -1033,4 +1032,23 @@ type FormattingSpecs() =
[<Fact>]
let ``false is false`` () = test <@ false = false @>
"""

[<Test>]
let ``line comment above single line abstract slot should not make it multiline, 757`` () =
formatSourceString false """[<AllowNullLiteral>]
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 """
[<AllowNullLiteral>]
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
"""
12 changes: 8 additions & 4 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b4bb37a

Please sign in to comment.