Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't let trivia content before make a member definition multiline #760

Merged
merged 3 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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