diff --git a/src/Fantomas.Tests/UnionTests.fs b/src/Fantomas.Tests/UnionTests.fs index 9d5434bf56..5fda650701 100644 --- a/src/Fantomas.Tests/UnionTests.fs +++ b/src/Fantomas.Tests/UnionTests.fs @@ -168,7 +168,7 @@ type CustomerId = private | CustomerId of int """ [] -let ``Single case DU with member should be on a newline`` () = +let ``single case DU with member should be on a newline`` () = formatSourceString false """ type CustomerId = | CustomerId of int @@ -217,4 +217,17 @@ type internal Foo = private | Bar |> should equal """namespace meh type internal Foo = private | Bar +""" + +[] +let ``single case DU with comment above clause, 567`` () = + formatSourceString false """type 'a MyGenericType = + /// + Foo +""" config + |> prepend newline + |> should equal """ +type 'a MyGenericType = + /// + Foo """ \ No newline at end of file diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index cb5a87365e..8f8f060561 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1553,13 +1553,18 @@ and genTypeDefn astContext (TypeDef(ats, px, ao, tds, tcs, tdr, ms, s, preferPos | Simple TDSRNone -> typeName - | Simple(TDSRTypeAbbrev t) -> - typeName +> sepEq +> sepSpace - +> genTrivia tdr.Range - (genType astContext false t - +> ifElse (List.isEmpty ms) (!- "") + | Simple(TDSRTypeAbbrev t) -> + let genTypeAbbrev = genType astContext false t + + let genMembers = + ifElse (List.isEmpty ms) + (!- "") (indent ++ "with" +> indent +> genMemberDefnList { astContext with InterfaceRange = None } ms - +> unindent +> unindent)) + +> unindent +> unindent) + + let genTypeBody = autoIndentNlnByFuture (genTrivia tdr.Range genTypeAbbrev) +> genMembers + + typeName +> sepEq +> sepSpace +> genTypeBody | Simple(TDSRException(ExceptionDefRepr(ats, px, ao, uc))) -> genExceptionBody astContext ats px ao uc |> genTrivia tdr.Range