Skip to content

Commit

Permalink
Expand let statements more
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Apr 18, 2023
1 parent c1dbf4e commit db79a17
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ absorbThen :: Expression -> Doc
absorbThen (Term t) | isAbsorbable t = hardspace <> prettyTerm t <> hardspace
absorbThen x = line <> nest 2 (group x) <> line

-- What is allowed to come on the same line as `in`?
-- Absorbable terms like sets
-- if, with, let
absorbIn :: Expression -> Doc
absorbIn (Term t) | isAbsorbable t = hardspace <> prettyTerm t <> hardspace
absorbIn x@(If _ _ _ _ _ _) = group x
absorbIn x@(With _ _ _ _) = group x
absorbIn x@(Let _ _ _ _) = group x
absorbIn x = line <> nest 2 (group x) <> line

absorbElse :: Expression -> Doc
absorbElse (If if_ cond then_ expr0 else_ expr1)
= hardspace <> pretty if_ <> hardspace <> group cond <> hardspace
Expand All @@ -212,9 +222,9 @@ instance Pretty Expression where

pretty (Let (Ann let_ letTrailing letLeading) binders
(Ann in_ inTrailing inLeading) expr)
= base $ group letPart <> line <> group inPart
where letPart = pretty let_ <> pretty letTrailing <> line <> letBody
inPart = pretty in_ <> hardspace <> pretty expr
= base $ group letPart <> line <> inPart
where letPart = pretty let_ <> pretty letTrailing <> hardline <> letBody
inPart = pretty in_ <> hardspace <> absorbIn expr
letBody = nest 2 $
pretty letLeading
<> sepBy hardline binders
Expand Down

0 comments on commit db79a17

Please sign in to comment.