diff --git a/src-literatetests/10-tests.blt b/src-literatetests/10-tests.blt index 95d8593..680d6f1 100644 --- a/src-literatetests/10-tests.blt +++ b/src-literatetests/10-tests.blt @@ -676,6 +676,22 @@ import Data.List ( nub , indexElem ) +#test a-ridiculous-amount-of-elements +import Test ( Long + , list + , with + , items + , that + , will + , not + , quite + , fit + , onA + , single + , line + , anymore + ) + #test with-things import Test ( T , T2() diff --git a/src-literatetests/tests-context-free.blt b/src-literatetests/tests-context-free.blt index 6e8c523..f4c4d6d 100644 --- a/src-literatetests/tests-context-free.blt +++ b/src-literatetests/tests-context-free.blt @@ -707,6 +707,23 @@ import Data.List (nub) #test several-elements import Data.List (nub, foldl', indexElem) +#test a-ridiculous-amount-of-elements +import Test + ( Long + , list + , with + , items + , that + , will + , not + , quite + , fit + , onA + , single + , line + , anymore + ) + #test with-things import Test (T, T2(), T3(..), T4(T4), T5(T5, t5), T6((<|>)), (+)) @@ -721,15 +738,8 @@ import TestJustShortEnoughModuleNameLikeThisOn as T import TestJustAbitToLongModuleNameLikeThisOneI as T import TestJustShortEnoughModuleNameLike hiding () import TestJustAbitToLongModuleNameLikeTh hiding () -import MoreThanSufficientlyLongModuleNameWithSome ( items - , that - , will - , not - , fit - , inA - , compact - , layout - ) +import MoreThanSufficientlyLongModuleNameWithSome + (items, that, will, not, fit, inA, compact, layout) #test import-with-comments -- Test @@ -739,62 +749,70 @@ import qualified Data.List as L (foldl') {- Test -} #test import-with-comments-2 -import Test ( abc - , def - -- comment - ) +import Test + ( abc + , def + -- comment + ) #test import-with-comments-3 -import Test ( abc - -- comment - ) +import Test + ( abc + -- comment + ) #test import-with-comments-4 -import Test ( abc - -- comment - , def - , ghi - {- comment -} - , jkl - -- comment - ) +import Test + ( abc + -- comment + , def + , ghi + {- comment -} + , jkl + -- comment + ) -- Test import Test (test) #test import-with-comments-5 -import Test ( -- comment - ) +import Test + ( -- comment + ) #test long-bindings import Test (longbindingNameThatoverflowsColum) import Test (Long(List, Of, Things)) #test things-with-with-comments -import Test ( Thing( With - -- Comments - , and - -- also - , items - -- ! - ) - ) -import Test ( Thing( Item - -- and Comment - ) - ) -import Test ( Thing( With - -- Comments - , and - -- also - , items - -- ! - ) - ) +import Test + ( Thing( With + -- Comments + , and + -- also + , items + -- ! + ) + ) +import Test + ( Thing( Item + -- and Comment + ) + ) +import Test + ( Thing( With + -- Comments + , and + -- also + , items + -- ! + ) + ) #test prefer-dense-empty-list -import VeryLongModuleNameThatCouldEvenCauseAnEmptyBindingListToExpandIntoMultipleLine () +import VeryLongModuleNameThatCouldEvenCauseAnEmptyBindingListToExpandIntoMultipleLine + () #test preamble full-preamble {-# LANGUAGE BangPatterns #-} diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs index 97284a8..5fa05a2 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Import.hs @@ -47,9 +47,6 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of ImportDecl _ (L _ modName) pkg src safe q False mas mllies -> do importCol <- mAsk <&> _conf_layout .> _lconfig_importColumn .> confUnpack indentPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> confUnpack - -- NB we don't need to worry about sharing in the below code - -- (docSharedWrapper etc.) because we do not use any docAlt nodes; all - -- "decisions" are made statically. let compact = indentPolicy == IndentPolicyLeft modNameT = Text.pack $ moduleNameString modName @@ -116,7 +113,12 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of if compact then let asDoc = maybe docEmpty makeAsDoc masT - in docSeq [importHead, asDoc, docSetBaseY $ bindingsD] + in docAlt + [ docForceSingleline $ + docSeq [importHead, asDoc, docSetBaseY $ bindingsD] + , docAddBaseY BrIndentRegular $ + docPar (docSeq [importHead, asDoc]) bindingsD + ] else case masT of Just n | enoughRoom -> docLines [docSeq [importHead, asDoc], bindingLine]