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,21 +787,27 @@ import Test ( -- comment
) )
#test long-bindings #test long-bindings
import Test ( longbindingNameThatoverflowsColum ) import Test ( longbindingNameThatoverflowsColum
import Test ( Long( List )
import Test ( Long
( List
, Of , Of
, Things , 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
( Item
-- and Comment -- and Comment
) )
) )
import Test ( Thing( With import Test ( Thing
( With
-- Comments -- Comments
, and , and
-- also -- also

View File

@ -792,7 +792,8 @@ import Test (Long(List, Of, Things))
#test things-with-with-comments #test things-with-with-comments
import Test import Test
( Thing( With ( Thing
( With
-- Comments -- Comments
, and , and
-- also -- also
@ -801,12 +802,14 @@ import Test
) )
) )
import Test import Test
( Thing( Item ( Thing
( Item
-- and Comment -- and Comment
) )
) )
import Test import Test
( Thing( With ( Thing
( With
-- Comments -- Comments
, and , and
-- also -- also

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
@ -119,15 +125,21 @@ layoutLLIEs llies = do
[] -> 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) -> (ieDsH:ieDsT) -> docAltFilter
docAltFilter [ ( not hasComments
[ (not hasComments, docSeq $ docLit (Text.pack "("):ieDs ++ [docParenR]) , docSeq
, (otherwise, docPar (docSetBaseY $ docSeq [docParenLSep, ieDsH]) $ $ [docLit (Text.pack "(")]
docLines $ ieDsT ++ (docForceSingleline <$> ieDs)
++ [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
] ]