Move expanded binding list to standard indent level for compact layout

pull/83/head
sniperrifle2004 2017-12-22 16:35:39 +01:00
parent ad34a8b9b9
commit 98c93f0d63
3 changed files with 87 additions and 51 deletions

View File

@ -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()

View File

@ -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,19 +749,22 @@ import qualified Data.List as L (foldl') {- Test -}
#test import-with-comments-2
import Test ( abc
import Test
( abc
, def
-- comment
)
#test import-with-comments-3
import Test ( abc
import Test
( abc
-- comment
)
#test import-with-comments-4
import Test ( abc
import Test
( abc
-- comment
, def
, ghi
@ -764,7 +777,8 @@ import Test ( abc
import Test (test)
#test import-with-comments-5
import Test ( -- comment
import Test
( -- comment
)
#test long-bindings
@ -772,7 +786,8 @@ import Test (longbindingNameThatoverflowsColum)
import Test (Long(List, Of, Things))
#test things-with-with-comments
import Test ( Thing( With
import Test
( Thing( With
-- Comments
, and
-- also
@ -780,11 +795,13 @@ import Test ( Thing( With
-- !
)
)
import Test ( Thing( Item
import Test
( Thing( Item
-- and Comment
)
)
import Test ( Thing( With
import Test
( Thing( With
-- Comments
, and
-- also
@ -794,7 +811,8 @@ import Test ( Thing( With
)
#test prefer-dense-empty-list
import VeryLongModuleNameThatCouldEvenCauseAnEmptyBindingListToExpandIntoMultipleLine ()
import VeryLongModuleNameThatCouldEvenCauseAnEmptyBindingListToExpandIntoMultipleLine
()
#test preamble full-preamble
{-# LANGUAGE BangPatterns #-}

View File

@ -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]