Fix comment handling with let-in
parent
670b796edb
commit
8861f16624
|
@ -612,6 +612,39 @@ func =
|
|||
_ -> True
|
||||
]
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
#group expression.let
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
|
||||
#test single-bind-comment-long
|
||||
testMethod foo bar baz qux =
|
||||
let x = undefined foo bar baz qux qux baz bar :: String
|
||||
-- some comment explaining the in expression
|
||||
in undefined foo x :: String
|
||||
|
||||
#test single-bind-comment-short
|
||||
testMethod foo bar baz qux =
|
||||
let x = undefined :: String
|
||||
-- some comment explaining the in expression
|
||||
in undefined :: String
|
||||
|
||||
#test single-bind-comment-before
|
||||
testMethod foo bar baz qux =
|
||||
-- some comment explaining the in expression
|
||||
let x = undefined :: String in undefined :: String
|
||||
|
||||
#test multiple-binds-comment
|
||||
foo foo bar baz qux =
|
||||
let a = 1
|
||||
b = 2
|
||||
c = 3
|
||||
-- some comment explaining the in expression
|
||||
in undefined :: String
|
||||
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
|
|
|
@ -727,8 +727,8 @@ layoutExpr lexpr@(L _ expr) = do
|
|||
#endif
|
||||
expDoc1 <- docSharedWrapper layoutExpr exp1
|
||||
-- We jump through some ugly hoops here to ensure proper sharing.
|
||||
mBindDocs <- mapM (fmap (fmap return) . docWrapNodeRest lexpr . return)
|
||||
=<< layoutLocalBinds binds
|
||||
hasComments <- hasAnyCommentsBelow lexpr
|
||||
mBindDocs <- fmap (fmap (fmap pure)) $ layoutLocalBinds binds
|
||||
let
|
||||
ifIndentFreeElse :: a -> a -> a
|
||||
ifIndentFreeElse x y =
|
||||
|
@ -745,15 +745,17 @@ 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.
|
||||
docSetBaseAndIndent $ case mBindDocs of
|
||||
Just [bindDoc] -> docAlt
|
||||
[ docSeq
|
||||
Just [bindDoc] -> runFilteredAlternative $ do
|
||||
addAlternativeCond (not hasComments) $ docSeq
|
||||
[ appSep $ docLit $ Text.pack "let"
|
||||
, appSep $ docForceSingleline bindDoc
|
||||
, docNodeAnnKW lexpr (Just AnnLet)
|
||||
$ appSep $ docForceSingleline bindDoc
|
||||
, appSep $ docLit $ Text.pack "in"
|
||||
, docForceSingleline expDoc1
|
||||
]
|
||||
, docLines
|
||||
[ docAlt
|
||||
addAlternative $ docLines
|
||||
[ docNodeAnnKW lexpr (Just AnnLet)
|
||||
$ docAlt
|
||||
[ docSeq
|
||||
[ appSep $ docLit $ Text.pack "let"
|
||||
, ifIndentFreeElse docSetBaseAndIndent docForceSingleline
|
||||
|
@ -775,7 +777,6 @@ layoutExpr lexpr@(L _ expr) = do
|
|||
(docSetBaseY expDoc1)
|
||||
]
|
||||
]
|
||||
]
|
||||
Just bindDocs@(_:_) -> runFilteredAlternative $ do
|
||||
--either
|
||||
-- let
|
||||
|
@ -805,7 +806,8 @@ layoutExpr lexpr@(L _ expr) = do
|
|||
IndentPolicyLeft -> docLines noHangingBinds
|
||||
IndentPolicyMultiple -> docLines noHangingBinds
|
||||
IndentPolicyFree -> docLines
|
||||
[ docSeq
|
||||
[ docNodeAnnKW lexpr (Just AnnLet)
|
||||
$ docSeq
|
||||
[ appSep $ docLit $ Text.pack "let"
|
||||
, docSetBaseAndIndent $ docLines bindDocs
|
||||
]
|
||||
|
@ -816,7 +818,8 @@ layoutExpr lexpr@(L _ expr) = do
|
|||
]
|
||||
addAlternative
|
||||
$ docLines
|
||||
[ docAddBaseY BrIndentRegular
|
||||
[ docNodeAnnKW lexpr (Just AnnLet)
|
||||
$ docAddBaseY BrIndentRegular
|
||||
$ docPar
|
||||
(docLit $ Text.pack "let")
|
||||
(docSetBaseAndIndent $ docLines $ bindDocs)
|
||||
|
|
Loading…
Reference in New Issue