Skip to content

Commit

Permalink
Don't add newline between empty multiline class constructor. Fixes fs…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Feb 27, 2021
1 parent 20a09de commit c4d4b0b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
22 changes: 22 additions & 0 deletions src/Fantomas.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,25 @@ type SomeVeryLongTypeNameWithConstructor
class
end
"""

[<Test>]
let ``long type generic type constraints with unit constructors, 1494`` () =
formatSourceString
false
"""
type ISingleExpressionValue<'p, 'o, 'v when 'p :> IProperty and 'o :> IOperator and 'p: equality and 'o: equality and 'v: equality> () =
abstract Property: 'p
abstract Operator: 'o
abstract Value: 'v
"""
config
|> prepend newline
|> should
equal
"""
type ISingleExpressionValue<'p, 'o, 'v when 'p :> IProperty and 'o :> IOperator and 'p: equality and 'o: equality and 'v: equality>
() =
abstract Property : 'p
abstract Operator : 'o
abstract Value : 'v
"""
26 changes: 19 additions & 7 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4440,17 +4440,29 @@ and genMemberDefn astContext node =
+> col sepComma (simplePats ps) (genSimplePat astContext)
+> sepCloseT

let emptyPats =
let rec isEmpty ps =
match ps with
| SynSimplePats.SimplePats ([], _) -> true
| SynSimplePats.SimplePats _ -> false
| SynSimplePats.Typed (spts, _, _) -> isEmpty spts

isEmpty ps

let longExpr ctx =
(indent
+> sepNln
+> optSingle (fun ao -> genAccess ao +> sepNln) ao
+> sepOpenT
+> indent
+> sepNln
+> col (sepComma +> sepNln) (simplePats ps) (genSimplePat astContext)
+> unindent
+> sepNln
+> sepCloseT
+> ifElse
emptyPats
(sepOpenT +> sepCloseT)
(sepOpenT
+> indent
+> sepNln
+> col (sepComma +> sepNln) (simplePats ps) (genSimplePat astContext)
+> unindent
+> sepNln
+> sepCloseT)
+> onlyIf ctx.Config.AlternativeLongMemberDefinitions sepNln
+> unindent)
ctx
Expand Down

0 comments on commit c4d4b0b

Please sign in to comment.