on master help sign in
Make sure no comments are swallowed at the end
93271b2mrkkrp
data/examples/other/following-comment-last-0-out.hsnew file+3
@@ -0,0 +1,3 @@
1+-- | Another datatype...
2+data D'
3+-- ^ ...with two docstrings.
data/examples/other/following-comment-last-0.hsnew file+3
@@ -0,0 +1,3 @@
1+-- | Another datatype...
2+data D'
3+-- ^ ...with two docstrings.
data/examples/other/following-comment-last-1-out.hsnew file+6
@@ -0,0 +1,6 @@
1+-- | Another datatype...
2+data D'
3+ deriving (Show)
4+-- ^ ...with two docstrings.
5+
6+-- more
data/examples/other/following-comment-last-1.hsnew file+6
@@ -0,0 +1,6 @@
1+-- | Another datatype...
2+data D'
3+ deriving (Show)
4+-- ^ ...with two docstrings.
5+
6+-- more
data/examples/other/following-comment-last-2-out.hsnew file+7
@@ -0,0 +1,7 @@
1+-- | Another datatype...
2+data D'
3+ deriving (Show)
4+-- ^ ...with two docstrings.
5+
6+-- more
7+data B
data/examples/other/following-comment-last-2.hsnew file+8
@@ -0,0 +1,8 @@
1+-- | Another datatype...
2+data D'
3+ deriving (Show)
4+-- ^ ...with two docstrings.
5+
6+-- more
7+
8+data B
data/examples/other/following-comment-last-3-out.hsnew file+4
@@ -0,0 +1,4 @@
1+-- | Another datatype...
2+data D'
3+-- ^ ...with two docstrings.
4+-- even on second line
data/examples/other/following-comment-last-3.hsnew file+4
@@ -0,0 +1,4 @@
1+-- | Another datatype...
2+data D'
3+-- ^ ...with two docstrings.
4+-- even on second line
src/Ormolu/Printer/Meat/Module.hs+8−1
@@ -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
59+ when hasDecls $ do
60+ newlineModified <- isNewlineModified
61+ newline
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