on master help sign in
Make sure no comments are swallowed at the end
commit93271b25513d00935cb9bb38dfa6c6ce4fa3fb64 authormrkkrp <mark.karpov@tweag.io> dateTue 6 Aug 2019, 20:12 (7 years ago) parentca1a2e9
9 files changed+49−1
data/examples/other/following-comment-last-0-out.hs+3 data/examples/other/following-comment-last-0.hs+3 data/examples/other/following-comment-last-1-out.hs+6 data/examples/other/following-comment-last-1.hs+6 data/examples/other/following-comment-last-2-out.hs+7 data/examples/other/following-comment-last-2.hs+8 data/examples/other/following-comment-last-3-out.hs+4 data/examples/other/following-comment-last-3.hs+4 src/Ormolu/Printer/Meat/Module.hs+8−1
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
1515import Ormolu.Imports
1616import Ormolu.Printer.Combinators
1717import Ormolu.Printer.Comments
18+import Ormolu.Printer.Internal (isNewlineModified)
1819import Ormolu.Printer.Meat.Common
1920import Ormolu.Printer.Meat.Declaration
2021import Ormolu.Printer.Meat.Declaration.Warning
@@ -54,7 +55,13 @@ p_hsModule exts (L moduleSpan HsModule {..}) = do
5455 forM_ (sortImports hsmodImports) (located' p_hsmodImport)
5556 when (hasImports && hasDecls) newline
5657 p_hsDecls Free hsmodDecls
57− when hasDecls newline
5858 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
5966 when (trailingComments && hasModuleHeader) newline
6067 spitRemainingComments