Retain comments after lambdacase and at record fields

ghc92
Lennart Spitzner 2023-05-20 16:09:01 +02:00
parent adc74d8bb1
commit 6721a44359
2 changed files with 25 additions and 10 deletions

View File

@ -1015,3 +1015,15 @@ catchFunc = do
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
`catch` catcher
#test comment after lambdacase
func = \case
-- zzz
False -> 0
True -> 1
#test comment for recordfield
func = myRecord { field = -- comment
if some condition then option one else option two
, otherfield = "text"
}

View File

@ -124,19 +124,22 @@ layoutExpr lexpr@(L _ expr) = do
docSetParSpacing
$ docAddBaseY BrIndentRegular
$ (docLit $ Text.pack "\\case {}")
HsLamCase _ (MG _ lmatches@(L _ matches) _) -> do
HsLamCase epAnn (MG _ lmatches@(L _ matches) _) -> do
binderDoc <- docLit $ Text.pack "->"
layouters <- mAsk
funcPatDocs <-
layout_patternBind layouters Nothing binderDoc `mapM` matches
docSetParSpacing $ docAddBaseY BrIndentRegular $ docPar
(docLit $ Text.pack "\\case")
( docSetBaseAndIndent
$ docNonBottomSpacing
$ docHandleComms lmatches
$ docLines
$ return <$> funcPatDocs
)
docSetParSpacing
$ docAddBaseY BrIndentRegular
$ docHandleComms epAnn
$ docPar
(docLit $ Text.pack "\\case")
( docSetBaseAndIndent
$ docNonBottomSpacing
$ docHandleComms lmatches
$ docLines
$ return <$> funcPatDocs
)
HsApp _ exp1 _ -> do
let gather
:: [(EpAnnCO, LHsExpr GhcPs)]
@ -1015,7 +1018,7 @@ recordExpression dotdot wrapO wrapDD wrapC indentPolicy _lexpr nameDoc nameLayou
[AddCommaAnn span] -> Just $ epaLocationRealSrcSpanStart span
_ -> Nothing
SrcSpanAnn EpAnnNotUsed _ -> Nothing
fnameDoc <- shareDoc $ nameLayouter nameThing
fnameDoc <- shareDoc $ docHandleComms fEpAnn $ nameLayouter nameThing
if pun
then pure $ Left (posStart, fnameDoc)
else do