Fix if-then-else comment placement issue

pull/3/head
Lennart Spitzner 2016-08-18 01:14:11 +02:00
parent e67855fd98
commit d0fcfc563e
2 changed files with 31 additions and 8 deletions

View File

@ -648,3 +648,12 @@ regressionTests = do
, gast <- award , gast <- award
] ]
|] |]
it "if-then-else comment placement" $ do
roundTripEqual $
[text|
func = if x
then if y -- y is important
then foo
else bar
else Nothing
|]

View File

@ -296,8 +296,10 @@ layoutExpr lexpr@(L _ expr) = docWrapNode lexpr $ case expr of
ifExprDoc <- docSharedWrapper layoutExpr ifExpr ifExprDoc <- docSharedWrapper layoutExpr ifExpr
thenExprDoc <- docSharedWrapper layoutExpr thenExpr thenExprDoc <- docSharedWrapper layoutExpr thenExpr
elseExprDoc <- docSharedWrapper layoutExpr elseExpr elseExprDoc <- docSharedWrapper layoutExpr elseExpr
docAlt hasComments <- hasAnyCommentsBelow lexpr
[ docSeq docAltFilter
[ (,) (not hasComments)
$ docSeq
[ appSep $ docLit $ Text.pack "if" [ appSep $ docLit $ Text.pack "if"
, appSep $ docForceSingleline ifExprDoc , appSep $ docForceSingleline ifExprDoc
, appSep $ docLit $ Text.pack "then" , appSep $ docLit $ Text.pack "then"
@ -305,11 +307,15 @@ layoutExpr lexpr@(L _ expr) = docWrapNode lexpr $ case expr of
, appSep $ docLit $ Text.pack "else" , appSep $ docLit $ Text.pack "else"
, docForceSingleline elseExprDoc , docForceSingleline elseExprDoc
] ]
, docSetParSpacing , (,) True
$ docSetParSpacing
$ docAddBaseY BrIndentRegular $ docAddBaseY BrIndentRegular
$ docPar $ docPar
( docAddBaseY (BrIndentSpecial 3) ( docAddBaseY (BrIndentSpecial 3)
$ docSeq [appSep $ docLit $ Text.pack "if", docForceSingleline ifExprDoc]) $ docSeq
[ docNodeAnnKW lexpr Nothing $ appSep $ docLit $ Text.pack "if"
, docNodeAnnKW lexpr (Just AnnIf) $ docForceSingleline ifExprDoc
])
(docLines (docLines
[ docAddBaseY BrIndentRegular [ docAddBaseY BrIndentRegular
$ docAlt $ docAlt
@ -324,10 +330,14 @@ layoutExpr lexpr@(L _ expr) = docWrapNode lexpr $ case expr of
$ docPar (docLit $ Text.pack "else") elseExprDoc $ docPar (docLit $ Text.pack "else") elseExprDoc
] ]
]) ])
, docAddBaseY BrIndentRegular , (,) True
$ docAddBaseY BrIndentRegular
$ docPar $ docPar
( docAddBaseY (BrIndentSpecial 3) ( docAddBaseY (BrIndentSpecial 3)
$ docSeq [appSep $ docLit $ Text.pack "if", ifExprDoc]) $ docSeq
[ docNodeAnnKW lexpr Nothing $ appSep $ docLit $ Text.pack "if"
, docNodeAnnKW lexpr (Just AnnIf) $ ifExprDoc
])
(docLines (docLines
[ docAddBaseY BrIndentRegular [ docAddBaseY BrIndentRegular
$ docAlt $ docAlt
@ -342,9 +352,13 @@ layoutExpr lexpr@(L _ expr) = docWrapNode lexpr $ case expr of
$ docPar (docLit $ Text.pack "else") elseExprDoc $ docPar (docLit $ Text.pack "else") elseExprDoc
] ]
]) ])
, docLines , (,) True
$ docLines
[ docAddBaseY (BrIndentSpecial 3) [ docAddBaseY (BrIndentSpecial 3)
$ docSeq [appSep $ docLit $ Text.pack "if", ifExprDoc] $ docSeq
[ docNodeAnnKW lexpr Nothing $ appSep $ docLit $ Text.pack "if"
, docNodeAnnKW lexpr (Just AnnIf) $ ifExprDoc
]
, docAddBaseY BrIndentRegular , docAddBaseY BrIndentRegular
$ docPar (docLit $ Text.pack "then") thenExprDoc $ docPar (docLit $ Text.pack "then") thenExprDoc
, docAddBaseY BrIndentRegular , docAddBaseY BrIndentRegular