From 38cdd152218799b91993e6483903fd5618b7d6d9 Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Thu, 13 Feb 2020 19:03:46 +0100 Subject: [PATCH] Fix moving comment in export list (haddock header) (#281) --- src-literatetests/15-regressions.blt | 10 +++++++++ .../Haskell/Brittany/Internal/Layouters/IE.hs | 21 ++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src-literatetests/15-regressions.blt b/src-literatetests/15-regressions.blt index 54b467d..3ae2892 100644 --- a/src-literatetests/15-regressions.blt +++ b/src-literatetests/15-regressions.blt @@ -824,3 +824,13 @@ foo = , ("xx", "xxxxx") , ("xx", "xx") ] + +#test issue 281 + +module Main + ( DataTypeI + , DataTypeII(DataConstructor) + -- * Haddock heading + , name + ) +where diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs b/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs index 0407a3c..f2c36de 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs @@ -65,29 +65,36 @@ layoutIE lie@(L _ ie) = docWrapNode lie $ case ie of #else IEThingWith x _ ns _ -> do #endif - hasComments <- hasAnyCommentsBelow lie + hasComments <- orM + ( hasCommentsBetween lie AnnOpenP AnnCloseP + : hasAnyCommentsBelow x + : map hasAnyCommentsBelow ns + ) runFilteredAlternative $ do addAlternativeCond (not hasComments) $ docSeq $ [layoutWrapped lie x, docLit $ Text.pack "("] ++ intersperse docCommaSep (map nameDoc ns) ++ [docParenR] - addAlternative $ docAddBaseY BrIndentRegular $ docPar - (layoutWrapped lie x) - (layoutItems (splitFirstLast ns)) + addAlternative + $ docWrapNodeRest lie + $ docAddBaseY BrIndentRegular + $ docPar + (layoutWrapped lie x) + (layoutItems (splitFirstLast ns)) where nameDoc = (docLit =<<) . lrdrNameToTextAnn . prepareName layoutItem n = docSeq [docCommaSep, docWrapNode n $ nameDoc n] layoutItems FirstLastEmpty = docSetBaseY $ docLines - [docSeq [docParenLSep, docWrapNodeRest lie docEmpty], docParenR] + [docSeq [docParenLSep, docNodeAnnKW lie (Just AnnOpenP) docEmpty], docParenR] layoutItems (FirstLastSingleton n) = docSetBaseY $ docLines - [docSeq [docParenLSep, docWrapNodeRest lie $ nameDoc n], docParenR] + [docSeq [docParenLSep, docNodeAnnKW lie (Just AnnOpenP) $ nameDoc n], docParenR] layoutItems (FirstLast n1 nMs nN) = docSetBaseY $ docLines $ [docSeq [docParenLSep, docWrapNode n1 $ nameDoc n1]] ++ map layoutItem nMs - ++ [docSeq [docCommaSep, docWrapNodeRest lie $ nameDoc nN], docParenR] + ++ [docSeq [docCommaSep, docNodeAnnKW lie (Just AnnOpenP) $ nameDoc nN], docParenR] #if MIN_VERSION_ghc(8,6,0) IEModuleContents _ n -> docSeq #else