@@ -15,6 +15,7 @@ import GHC
15import Ormolu.Imports
15import Ormolu.Imports
16import Ormolu.Printer.Combinators
16import Ormolu.Printer.Combinators
17import Ormolu.Printer.Comments
17import Ormolu.Printer.Comments
18+import Ormolu.Printer.Internal (isNewlineModified)
18import Ormolu.Printer.Meat.Common
19import Ormolu.Printer.Meat.Common
19import Ormolu.Printer.Meat.Declaration
20import Ormolu.Printer.Meat.Declaration
20import Ormolu.Printer.Meat.Declaration.Warning
21import Ormolu.Printer.Meat.Declaration.Warning
@@ -54,7 +55,13 @@ p_hsModule exts (L moduleSpan HsModule {..}) = do
54 forM_ (sortImports hsmodImports) (located' p_hsmodImport)
55 forM_ (sortImports hsmodImports) (located' p_hsmodImport)
55 when (hasImports && hasDecls) newline
56 when (hasImports && hasDecls) newline
56 p_hsDecls Free hsmodDecls
57 p_hsDecls Free hsmodDecls
57− when hasDecls newline
58 trailingComments <- hasMoreComments
58 trailingComments <- hasMoreComments
60+ newlineModified <- isNewlineModified
62+ -- In this case we need to insert a newline between the comments
63+ -- output as a side effect of the previous newline and trailing
64+ -- comments to prevent them from merging.
65+ when (newlineModified && trailingComments) newline
59 when (trailingComments && hasModuleHeader) newline
66 when (trailingComments && hasModuleHeader) newline
60 spitRemainingComments
67 spitRemainingComments