From 58167046585ba7962efcdae5d39e296bb3ea9028 Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Mon, 4 Jun 2018 17:30:50 +0200 Subject: [PATCH] Fix import-hiding-paragraph with policy/=free (fixes #150) --- src-literatetests/10-tests.blt | 15 +++++++++++++++ src-literatetests/30-tests-context-free.blt | 16 ++++++++++++++++ .../Brittany/Internal/Layouters/Import.hs | 13 ++++++++----- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src-literatetests/10-tests.blt b/src-literatetests/10-tests.blt index 4919f3f..561bd64 100644 --- a/src-literatetests/10-tests.blt +++ b/src-literatetests/10-tests.blt @@ -734,6 +734,21 @@ import Test hiding ( ) import Test as T hiding ( ) +#test import-hiding-many +import Prelude as X + hiding ( head + , init + , last + , maximum + , minimum + , pred + , read + , readFile + , succ + , tail + , undefined + ) + #test long-module-name-simple import TestJustShortEnoughModuleNameLikeThisOne ( ) import TestJustAbitToLongModuleNameLikeThisOneIs diff --git a/src-literatetests/30-tests-context-free.blt b/src-literatetests/30-tests-context-free.blt index 3ecae6f..1cf082e 100644 --- a/src-literatetests/30-tests-context-free.blt +++ b/src-literatetests/30-tests-context-free.blt @@ -736,6 +736,22 @@ import Test (T, T2(), T3(..), T4(T4), T5(T5, t5), T6((<|>)), (+)) import Test hiding () import Test as T hiding () +#test import-hiding-many +import Prelude as X + hiding + ( head + , init + , last + , maximum + , minimum + , pred + , read + , readFile + , succ + , tail + , undefined + ) + #test long-module-name-simple import TestJustShortEnoughModuleNameLikeThisOne () import TestJustAbitToLongModuleNameLikeThisOneIs () diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs index aa4380f..10e8285 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs @@ -87,7 +87,10 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of Just (_, llies) -> do hasComments <- hasAnyCommentsBelow llies if compact - then docSeq [hidDoc, layoutLLIEs True llies] + then docAlt + [ docSeq [hidDoc, docForceSingleline $ layoutLLIEs True llies] + , docPar hidDoc (layoutLLIEs True llies) + ] else do ieDs <- layoutAnnAndSepLLIEs llies docWrapNodeRest llies @@ -99,7 +102,7 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of (docSeq [hidDoc, docParenLSep, docWrapNode llies docEmpty]) (docEnsureIndent (BrIndentSpecial hidDocColDiff) docParenR) else docSeq [hidDoc, docParenLSep, docSeparator, docParenR] - -- ..[hiding].( b ) + -- ..[hiding].( b ) [ieD] -> runFilteredAlternative $ do addAlternativeCond (not hasComments) $ docSeq @@ -112,9 +115,9 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of addAlternative $ docPar (docSeq [hidDoc, docParenLSep, docNonBottomSpacing ieD]) (docEnsureIndent (BrIndentSpecial hidDocColDiff) docParenR) - -- ..[hiding].( b - -- , b' - -- ) + -- ..[hiding].( b + -- , b' + -- ) (ieD:ieDs') -> docPar (docSeq [hidDoc, docSetBaseY $ docSeq [docParenLSep, ieD]])