Filter binders with docSetBaseAndIndent.

pull/66/head
Evan Rutledge Borden 2017-11-25 20:50:17 -05:00 committed by Lennart Spitzner
parent de0851f975
commit e9a2de7a85
3 changed files with 63 additions and 48 deletions

View File

@ -532,7 +532,8 @@ func = do
#test let
func = do
let x = 13
let
x = 13
stmt x
@ -1021,7 +1022,8 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs = do
]
| not hasComments
, [(guards, body, _bodyRaw)] <- [clauseDocs]
, let guardPart = singleLineGuardsDoc guards
, let
guardPart = singleLineGuardsDoc guards
, wherePart <- case mWhereDocs of
Nothing -> return @[] $ docEmpty
Just [w] -> return @[] $ docSeq
@ -1042,7 +1044,8 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs = do
]
++ wherePartMultiLine
| [(guards, body, _bodyRaw)] <- [clauseDocs]
, let guardPart = singleLineGuardsDoc guards
, let
guardPart = singleLineGuardsDoc guards
, Data.Maybe.isJust mWhereDocs
]
++ -- two-line solution + where in next line(s)
@ -1054,18 +1057,20 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs = do
]
++ wherePartMultiLine
| [(guards, body, _bodyRaw)] <- [clauseDocs]
, let guardPart = singleLineGuardsDoc guards
, let
guardPart = singleLineGuardsDoc guards
]
#test comment-testcase-17
{-# LANGUAGE MultiWayIf #-}
func = do
let foo = if
| Constuctoooooooooooooooooooooooooooooooooooor `elem` artics -- TODO
-> max
(defLen - 0.2) -- TODO
(defLen * 0.8)
| otherwise -> max (defLen - 0.05) (defLen * 0.95) -- TODO
let
foo = if
| Constuctoooooooooooooooooooooooooooooooooooor `elem` artics -- TODO
-> max
(defLen - 0.2) -- TODO
(defLen * 0.8)
| otherwise -> max (defLen - 0.05) (defLen * 0.95) -- TODO
return True
#test issue 49

View File

@ -539,33 +539,39 @@ layoutExpr lexpr@(L _ expr) = do
-- if "let" is moved horizontally as part of the transformation, as the
-- comments before the first let item are moved horizontally with it.
docSetIndentLevel $ case mBindDocs of
Just [bindDoc] -> docAlt
[ docSeq
[ appSep $ docLit $ Text.pack "let"
, appSep $ docForceSingleline $ return bindDoc
, appSep $ docLit $ Text.pack "in"
, docForceSingleline $ expDoc1
]
, docLines
[ docSeq
[ appSep $ docLit $ Text.pack "let"
, docSetBaseAndIndent $ return bindDoc
]
Just [bindDoc] -> docAltFilter
[ ( indentPolicy /= IndentPolicyLeft
, docSeq
[ appSep $ docLit $ Text.pack "in "
, docSetBaseY $ expDoc1
[ appSep $ docLit $ Text.pack "let"
, appSep $ docForceSingleline $ return bindDoc
, appSep $ docLit $ Text.pack "in"
, docForceSingleline $ expDoc1
]
]
, docLines
[ docAddBaseY BrIndentRegular
$ docPar
(appSep $ docLit $ Text.pack "let")
(docSetBaseAndIndent $ return bindDoc)
, docAddBaseY BrIndentRegular
$ docPar
(appSep $ docLit $ Text.pack "in")
(docSetBaseY $ expDoc1)
]
)
, ( indentPolicy /= IndentPolicyLeft
, docLines
[ docSeq
[ appSep $ docLit $ Text.pack "let"
, docSetBaseAndIndent $ return bindDoc
]
, docSeq
[ appSep $ docLit $ Text.pack "in "
, docSetBaseY $ expDoc1
]
]
)
, ( True
, docLines
[ docAddBaseY BrIndentRegular
$ docPar
(appSep $ docLit $ Text.pack "let")
(docSetBaseAndIndent $ return bindDoc)
, docAddBaseY BrIndentRegular
$ docPar
(appSep $ docLit $ Text.pack "in")
(docSetBaseY $ expDoc1)
]
)
]
Just bindDocs@(_:_) -> docAltFilter
--either

View File

@ -50,19 +50,23 @@ layoutStmt lstmt@(L _ stmt) = do
]
LetStmt binds -> layoutLocalBinds binds >>= \case
Nothing -> docLit $ Text.pack "let" -- i just tested
-- it, and it is
-- indeed allowed.
-- heh.
-- it, and it is
-- indeed allowed.
-- heh.
Just [] -> docLit $ Text.pack "let" -- this probably never happens
Just [bindDoc] -> docAlt
[ docCols
ColDoLet
[ appSep $ docLit $ Text.pack "let"
, docSetBaseAndIndent $ return bindDoc
]
, docAddBaseY BrIndentRegular $ docPar
(docLit $ Text.pack "let")
(docSetBaseAndIndent $ return bindDoc)
Just [bindDoc] -> docAltFilter
[ ( indentPolicy /= IndentPolicyLeft
, docCols
ColDoLet
[ appSep $ docLit $ Text.pack "let"
, docSetBaseAndIndent $ return bindDoc
]
)
, ( True
, docAddBaseY BrIndentRegular $ docPar
(docLit $ Text.pack "let")
(docSetBaseAndIndent $ return bindDoc)
)
]
Just bindDocs -> docAltFilter
[ ( indentPolicy /= IndentPolicyLeft