Fix bad indentation problem for HsMultiIf inside parens

Lennart Spitzner 2023-05-20 17:29:44 +02:00
parent 7485938bf3
commit a8119e872c
3 changed files with 53 additions and 32 deletions

View File

@ -1027,3 +1027,19 @@ func = myRecord { field = -- comment
if some condition then option one else option two if some condition then option one else option two
, otherfield = "text" , otherfield = "text"
} }
#test multiline guards within parenthesis
duGswidunBlxaq drux = DeeX.Vufcqqafi
(tiErihambSunxo drux)
(if
| geIqzscmBhiwo drux
-> Bmuh "Hpiioqa a yabufx ynyuq"
| liWaov drux
-> Bmuh "Ookhup ubqocf merr ukm ynyuq iitiop"
| tiErihambSunxo drux && bdp (alJukIkuh drux)
-> Bmuh "Jpgic dfaz dieb fs wreup hsv of ynyuq dio njr subdet"
| ukFinwuicUgIcclcep drux
-> Bmuh "Egwiqae-ka-molenqe codns dif'y ns csjyhth sisoyy"
| otherwise
-> Likiotq
)

View File

@ -641,29 +641,36 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
$ docLines $ docLines
$ map docSetBaseY $ map docSetBaseY
$ clauseDocs $ clauseDocs
>>= \(grhsEpAnn, guardDocs, bodyDoc) -> -- TODO92 >>= \(grhsEpAnn, guardDocs, bodyDoc) -> case guardDocs of
(case guardDocs of [] ->
[] -> [docHandleComms grhsEpAnn docEmpty] [ docHandleComms grhsEpAnn
[g] -> $ docCols
[ docHandleComms grhsEpAnn ColOpPrefix
$ docSeq [appSep [ appSep $ return binderDoc
$ docLit $ Text.pack "|", return g] , docAddBaseY BrIndentRegular $ return bodyDoc
] ]
(g1 : gr) -> ]
( ( docHandleComms grhsEpAnn [g] ->
$ docSeq [appSep $ docLit $ Text.pack "|", return g1] [ docHandleComms grhsEpAnn
) $ docSeq [appSep $ docLit $ Text.pack "|", return g]
: (gr <&> \g -> , docSeq
docSeq [appSep $ docLit $ Text.pack ",", return g] [ appSep $ return binderDoc
) , docAddBaseY BrIndentRegular $ return bodyDoc
) ]
) ]
++ [ docCols (g1 : gr) ->
ColOpPrefix ( [ docHandleComms grhsEpAnn
[ appSep $ return binderDoc $ docSeq [appSep $ docLit $ Text.pack "|", return g1]
, docAddBaseY BrIndentRegular $ return bodyDoc ]
] ++ (gr <&> \g ->
] docSeq [appSep $ docLit $ Text.pack ",", return g]
)
++ [ docSeq
[ appSep $ return binderDoc
, docAddBaseY BrIndentRegular $ return bodyDoc
]
]
)
] ]
++ wherePartMultiLine ++ wherePartMultiLine

View File

@ -109,15 +109,13 @@ transformSimplifyColumns = Uniplate.rewrite $ \case
-> Just -> Just
$ BDLines [BDCols sig1 (List.init cols ++ [line]), BDCols sig2 cols2] $ BDLines [BDCols sig1 (List.init cols ++ [line]), BDCols sig2 cols2]
BDCols sig1 cols BDCols sig1 cols
| BDPar ind line (BDLines lines) <- List.last cols | BDPar _ line (BDLines lines) <- List.last cols
, BDCols sig2 cols2 <- List.last lines , all (\case
, sig1 == sig2 BDCols sig2 _ -> sig1 == sig2
-> Just $ BDLines _ -> False
[ BDCols sig1 )
$ List.init cols lines
++ [BDPar ind line (BDLines $ List.init lines)] -> Just $ BDLines $ BDCols sig1 (List.init cols ++ [line]) : lines
, BDCols sig2 cols2
]
BDLines [x] -> Just $ x BDLines [x] -> Just $ x
BDLines [] -> Just $ BDEmpty BDLines [] -> Just $ BDEmpty
BDSeq{} -> Nothing BDSeq{} -> Nothing