summaryrefslogtreecommitdiffhomepage
path: root/src/Language/Haskell/Stylish/Step/Imports.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/Haskell/Stylish/Step/Imports.hs')
-rw-r--r--src/Language/Haskell/Stylish/Step/Imports.hs18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/Language/Haskell/Stylish/Step/Imports.hs b/src/Language/Haskell/Stylish/Step/Imports.hs
index f8361a8..b1f2bd9 100644
--- a/src/Language/Haskell/Stylish/Step/Imports.hs
+++ b/src/Language/Haskell/Stylish/Step/Imports.hs
@@ -49,6 +49,7 @@ data ListAlign
data LongListAlign
= Inline
+ | InlineWithBreak
| Multiline
deriving (Eq, Show)
@@ -122,10 +123,14 @@ prettyImport :: Int -> Align -> Bool -> Bool -> Int -> H.ImportDecl l
prettyImport columns Align{..} padQualified padName longest imp =
case longListAlign of
Inline -> inlineWrap
- Multiline -> if listAlign == NewLine || length inlineWrap > 1
- then multilineWrap
- else inlineWrap
+ InlineWithBreak -> longListWrapper inlineWrap inlineWithBreakWrap
+ Multiline -> longListWrapper inlineWrap multilineWrap
where
+ longListWrapper shortWrap longWrap =
+ if listAlign == NewLine || length shortWrap > 1
+ then longWrap
+ else shortWrap
+
inlineWrap = inlineWrapper
$ mapSpecs
$ withInit (++ ",")
@@ -139,6 +144,13 @@ prettyImport columns Align{..} padQualified padName longest imp =
AfterAlias -> withTail (' ' :)
. wrap columns paddedBase (afterAliasBaseLength + 1)
+ inlineWithBreakWrap = paddedNoSpecBase : (wrapRest columns listPadding
+ $ mapSpecs
+ $ withInit (++ ",")
+ . withHead ("(" ++)
+ . withLast (++ ")"))
+
+ -- 'wrapRest 0' ensures that every item of spec list is on new line.
multilineWrap = paddedNoSpecBase : (wrapRest 0 listPadding
$ (mapSpecs
$ withHead ("( " ++)