Make sure no comments are swallowed at the end

This commit is contained in:
mrkkrp 2019-08-06 20:12:43 +02:00 committed by Mark Karpov
parent ca1a2e9e5c
commit 93271b2551
9 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,3 @@
-- | Another datatype...
data D'
-- ^ ...with two docstrings.

View File

@ -0,0 +1,3 @@
-- | Another datatype...
data D'
-- ^ ...with two docstrings.

View File

@ -0,0 +1,6 @@
-- | Another datatype...
data D'
deriving (Show)
-- ^ ...with two docstrings.
-- more

View File

@ -0,0 +1,6 @@
-- | Another datatype...
data D'
deriving (Show)
-- ^ ...with two docstrings.
-- more

View File

@ -0,0 +1,7 @@
-- | Another datatype...
data D'
deriving (Show)
-- ^ ...with two docstrings.
-- more
data B

View File

@ -0,0 +1,8 @@
-- | Another datatype...
data D'
deriving (Show)
-- ^ ...with two docstrings.
-- more
data B

View File

@ -0,0 +1,4 @@
-- | Another datatype...
data D'
-- ^ ...with two docstrings.
-- even on second line

View File

@ -0,0 +1,4 @@
-- | Another datatype...
data D'
-- ^ ...with two docstrings.
-- even on second line

View File

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