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 , 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 #test with-things
import Test ( T import Test ( T
, T2() , T2()

View File

@ -707,6 +707,23 @@ import Data.List (nub)
#test several-elements #test several-elements
import Data.List (nub, foldl', indexElem) 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 #test with-things
import Test (T, T2(), T3(..), T4(T4), T5(T5, t5), T6((<|>)), (+)) import Test (T, T2(), T3(..), T4(T4), T5(T5, t5), T6((<|>)), (+))
@ -721,15 +738,8 @@ import TestJustShortEnoughModuleNameLikeThisOn as T
import TestJustAbitToLongModuleNameLikeThisOneI as T import TestJustAbitToLongModuleNameLikeThisOneI as T
import TestJustShortEnoughModuleNameLike hiding () import TestJustShortEnoughModuleNameLike hiding ()
import TestJustAbitToLongModuleNameLikeTh hiding () import TestJustAbitToLongModuleNameLikeTh hiding ()
import MoreThanSufficientlyLongModuleNameWithSome ( items import MoreThanSufficientlyLongModuleNameWithSome
, that (items, that, will, not, fit, inA, compact, layout)
, will
, not
, fit
, inA
, compact
, layout
)
#test import-with-comments #test import-with-comments
-- Test -- Test
@ -739,19 +749,22 @@ import qualified Data.List as L (foldl') {- Test -}
#test import-with-comments-2 #test import-with-comments-2
import Test ( abc import Test
( abc
, def , def
-- comment -- comment
) )
#test import-with-comments-3 #test import-with-comments-3
import Test ( abc import Test
( abc
-- comment -- comment
) )
#test import-with-comments-4 #test import-with-comments-4
import Test ( abc import Test
( abc
-- comment -- comment
, def , def
, ghi , ghi
@ -764,7 +777,8 @@ import Test ( abc
import Test (test) import Test (test)
#test import-with-comments-5 #test import-with-comments-5
import Test ( -- comment import Test
( -- comment
) )
#test long-bindings #test long-bindings
@ -772,7 +786,8 @@ import Test (longbindingNameThatoverflowsColum)
import Test (Long(List, Of, Things)) import Test (Long(List, Of, Things))
#test things-with-with-comments #test things-with-with-comments
import Test ( Thing( With import Test
( Thing( With
-- Comments -- Comments
, and , and
-- also -- also
@ -780,11 +795,13 @@ import Test ( Thing( With
-- ! -- !
) )
) )
import Test ( Thing( Item import Test
( Thing( Item
-- and Comment -- and Comment
) )
) )
import Test ( Thing( With import Test
( Thing( With
-- Comments -- Comments
, and , and
-- also -- also
@ -794,7 +811,8 @@ import Test ( Thing( With
) )
#test prefer-dense-empty-list #test prefer-dense-empty-list
import VeryLongModuleNameThatCouldEvenCauseAnEmptyBindingListToExpandIntoMultipleLine () import VeryLongModuleNameThatCouldEvenCauseAnEmptyBindingListToExpandIntoMultipleLine
()
#test preamble full-preamble #test preamble full-preamble
{-# LANGUAGE BangPatterns #-} {-# 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 ImportDecl _ (L _ modName) pkg src safe q False mas mllies -> do
importCol <- mAsk <&> _conf_layout .> _lconfig_importColumn .> confUnpack importCol <- mAsk <&> _conf_layout .> _lconfig_importColumn .> confUnpack
indentPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> 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 let
compact = indentPolicy == IndentPolicyLeft compact = indentPolicy == IndentPolicyLeft
modNameT = Text.pack $ moduleNameString modName modNameT = Text.pack $ moduleNameString modName
@ -116,7 +113,12 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of
if compact if compact
then then
let asDoc = maybe docEmpty makeAsDoc masT 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 else
case masT of case masT of
Just n | enoughRoom -> docLines [docSeq [importHead, asDoc], bindingLine] Just n | enoughRoom -> docLines [docSeq [importHead, asDoc], bindingLine]