Stop hanging indent for IEThingWith

plus minor refactors/cleanups

this is more in line with IndentPolicyLeft and imo also looks
nicer in general
pull/124/head
Lennart Spitzner 2018-03-11 22:42:47 +01:00
parent af7f9017b8
commit 20f9c009ee
4 changed files with 90 additions and 57 deletions

View File

@ -787,27 +787,33 @@ import Test ( -- comment
) )
#test long-bindings #test long-bindings
import Test ( longbindingNameThatoverflowsColum ) import Test ( longbindingNameThatoverflowsColum
import Test ( Long( List )
, Of import Test ( Long
, Things ( List
) ) , Of
, Things
)
)
#test things-with-with-comments #test things-with-with-comments
import Test ( Thing( -- Comments import Test ( Thing
) ( -- Comments
)
) )
import Test ( Thing( Item import Test ( Thing
-- and Comment ( Item
) -- and Comment
)
) )
import Test ( Thing( With import Test ( Thing
-- Comments ( With
, and -- Comments
-- also , and
, items -- also
-- ! , items
) -- !
)
) )
#test prefer-dense-empty-list #test prefer-dense-empty-list
import VeryLongModuleNameThatCouldEvenCauseAnEmptyBindingListToExpandIntoMultipleLine import VeryLongModuleNameThatCouldEvenCauseAnEmptyBindingListToExpandIntoMultipleLine

View File

@ -792,27 +792,30 @@ import Test (Long(List, Of, Things))
#test things-with-with-comments #test things-with-with-comments
import Test import Test
( Thing( With ( Thing
-- Comments ( With
, and -- Comments
-- also , and
, items -- also
-- ! , items
) -- !
)
) )
import Test import Test
( Thing( Item ( Thing
-- and Comment ( Item
) -- and Comment
)
) )
import Test import Test
( Thing( With ( Thing
-- Comments ( With
, and -- Comments
-- also , and
, items -- also
-- ! , items
) -- !
)
) )
#test prefer-dense-empty-list #test prefer-dense-empty-list

View File

@ -47,10 +47,16 @@ layoutIE lie@(L _ ie) = docWrapNode lie $ case ie of
IEThingWith _ _ ns _ -> do IEThingWith _ _ ns _ -> do
hasComments <- hasAnyCommentsBelow lie hasComments <- hasAnyCommentsBelow lie
docAltFilter docAltFilter
[(not hasComments, docSeq $ [ien, docLit $ Text.pack "("] [ ( not hasComments
, docSeq
$ [ien, docLit $ Text.pack "("]
++ intersperse docCommaSep (map nameDoc ns) ++ intersperse docCommaSep (map nameDoc ns)
++ [docParenR]) ++ [docParenR]
,(otherwise, docSeq [ien, layoutItems (splitFirstLast ns)]) )
, (otherwise
, docAddBaseY BrIndentRegular
$ docPar ien (layoutItems (splitFirstLast ns))
)
] ]
where where
nameDoc = (docLit =<<) . lrdrNameToTextAnn . prepareName nameDoc = (docLit =<<) . lrdrNameToTextAnn . prepareName
@ -113,21 +119,27 @@ layoutAnnAndSepLLIEs llies@(L _ lies) = do
-- ) -- )
layoutLLIEs :: Located [LIE RdrName] -> ToBriDocM BriDocNumbered layoutLLIEs :: Located [LIE RdrName] -> ToBriDocM BriDocNumbered
layoutLLIEs llies = do layoutLLIEs llies = do
ieDs <- layoutAnnAndSepLLIEs llies ieDs <- layoutAnnAndSepLLIEs llies
hasComments <- hasAnyCommentsBelow llies hasComments <- hasAnyCommentsBelow llies
case ieDs of case ieDs of
[] -> docAltFilter [] -> docAltFilter
[ (not hasComments, docLit $ Text.pack "()") [ (not hasComments, docLit $ Text.pack "()")
, ( hasComments , ( hasComments
, docPar , docPar (docSeq [docParenLSep, docWrapNodeRest llies docEmpty])
(docSeq [docParenLSep, docWrapNodeRest llies docEmpty]) docParenR
docParenR )
) ]
] (ieDsH:ieDsT) -> docAltFilter
(ieDsH:ieDsT) -> [ ( not hasComments
docAltFilter , docSeq
[ (not hasComments, docSeq $ docLit (Text.pack "("):ieDs ++ [docParenR]) $ [docLit (Text.pack "(")]
, (otherwise, docPar (docSetBaseY $ docSeq [docParenLSep, ieDsH]) $ ++ (docForceSingleline <$> ieDs)
docLines $ ieDsT ++ [docParenR]
++ [docParenR]) )
] , ( otherwise
, docPar (docSetBaseY $ docSeq [docParenLSep, ieDsH])
$ docLines
$ ieDsT
++ [docParenR]
)
]

View File

@ -95,9 +95,22 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of
docParenR docParenR
else docSeq [hidDoc, docParenLSep, docSeparator, docParenR] else docSeq [hidDoc, docParenLSep, docSeparator, docParenR]
-- ..[hiding].( b ) -- ..[hiding].( b )
[ieD] -> if hasComments [ieD] -> docAltFilter
then docPar (docSeq [hidDoc, docParenLSep, ieD]) docParenR [ ( not hasComments
else docSeq [hidDoc, docParenLSep, ieD, docSeparator, docParenR] , docSeq
[ hidDoc
, docParenLSep
, docForceSingleline $ ieD
, docSeparator
, docParenR
]
)
, ( otherwise
, docPar
(docSeq [hidDoc, docParenLSep, docNonBottomSpacing ieD])
docParenR
)
]
-- ..[hiding].( b -- ..[hiding].( b
-- , b' -- , b'
-- ) -- )
@ -114,8 +127,7 @@ layoutImport limportD@(L _ importD) = docWrapNode limportD $ case importD of
then then
let asDoc = maybe docEmpty makeAsDoc masT let asDoc = maybe docEmpty makeAsDoc masT
in docAlt in docAlt
[ docForceSingleline $ [ docForceSingleline $ docSeq [importHead, asDoc, bindingsD]
docSeq [importHead, asDoc, docSetBaseY $ bindingsD]
, docAddBaseY BrIndentRegular $ , docAddBaseY BrIndentRegular $
docPar (docSeq [importHead, asDoc]) bindingsD docPar (docSeq [importHead, asDoc]) bindingsD
] ]