mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-21 07:17:25 +03:00
Fix printing of ifs with multiline conditions
Pretty-printing ifs with multiline conditions previously would not break the line before the then, leading to roundtripping errors. For example: ``` if a = b a then foo else bar ``` would print as: ``` if a = b a then foo else bar ``` This fixes the term printer to add a new case for when the condition is multiline.
This commit is contained in:
parent
3336bbbb43
commit
ca6dd75a66
@ -263,14 +263,20 @@ pretty0
|
|||||||
<> optSpace <> (fmt S.DelimiterChar $ l "]")
|
<> optSpace <> (fmt S.DelimiterChar $ l "]")
|
||||||
where optSpace = PP.orElse "" " "
|
where optSpace = PP.orElse "" " "
|
||||||
If' cond t f -> paren (p >= 2) $
|
If' cond t f -> paren (p >= 2) $
|
||||||
if PP.isMultiLine pt || PP.isMultiLine pf then PP.lines [
|
if PP.isMultiLine pcond then PP.lines [
|
||||||
(fmt S.ControlKeyword "if ") <> pcond <> (fmt S.ControlKeyword " then") `PP.hang` pt,
|
(fmt S.ControlKeyword "if") `PP.hang` pcond,
|
||||||
(fmt S.ControlKeyword "else") `PP.hang` pf
|
(fmt S.ControlKeyword "then") `PP.hang` pt,
|
||||||
]
|
|
||||||
else PP.spaced [
|
|
||||||
((fmt S.ControlKeyword "if") `PP.hang` pcond) <> ((fmt S.ControlKeyword " then") `PP.hang` pt),
|
|
||||||
(fmt S.ControlKeyword "else") `PP.hang` pf
|
(fmt S.ControlKeyword "else") `PP.hang` pf
|
||||||
]
|
]
|
||||||
|
else
|
||||||
|
if PP.isMultiLine pt || PP.isMultiLine pf then PP.lines [
|
||||||
|
(fmt S.ControlKeyword "if ") <> pcond <> (fmt S.ControlKeyword " then") `PP.hang` pt,
|
||||||
|
(fmt S.ControlKeyword "else") `PP.hang` pf
|
||||||
|
]
|
||||||
|
else PP.spaced [
|
||||||
|
((fmt S.ControlKeyword "if") `PP.hang` pcond) <> ((fmt S.ControlKeyword " then") `PP.hang` pt),
|
||||||
|
(fmt S.ControlKeyword "else") `PP.hang` pf
|
||||||
|
]
|
||||||
where
|
where
|
||||||
pcond = pretty0 n (ac 2 Block im doc) cond
|
pcond = pretty0 n (ac 2 Block im doc) cond
|
||||||
pt = branch t
|
pt = branch t
|
||||||
|
Loading…
Reference in New Issue
Block a user