Skip to content

Commit

Permalink
Rework bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed May 5, 2023
1 parent 7fe6a99 commit e9cdac6
Show file tree
Hide file tree
Showing 16 changed files with 869 additions and 693 deletions.
18 changes: 15 additions & 3 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,21 @@ instance Pretty Binder where

-- `foo = bar`
pretty (Assignment selectors assign expr semicolon)
= base $ group (hcat selectors <> hardspace
<> nest 2 (pretty assign <> softline <> pretty expr))
<> pretty semicolon
= base $ group $ hcat selectors <> hardspace
<> nest 2 (pretty assign <> absorbInner expr)
where
-- Function declaration / If statement / Let binding
-- If it is multi-line, force it into a new line with indentation, semicolon on separate line
absorbInner expr@(Abstraction _ _ _) = line <> pretty expr <> line' <> pretty semicolon
absorbInner expr@(If _ _ _ _ _ _) = line <> pretty expr <> line' <> pretty semicolon
absorbInner expr@(Let _ _ _ _) = line <> pretty expr <> line' <> pretty semicolon
-- Absorbable term (list/attrset)
-- force-absorb the term and then the semicolon
absorbInner expr@(Term t) | isAbsorbable t = hardspace <> group expr <> softline' <> pretty semicolon
-- `foo = bar`, otherwise
-- Try to absorb and keep the semicolon attached, spread otherwise
absorbInner expr = softline <> group (pretty expr <> softline' <> pretty semicolon)


-- | Pretty print a term without wrapping it in a group.
prettyTerm :: Term -> Doc
Expand Down
6 changes: 4 additions & 2 deletions test/diff/apply/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@
}
# https://github.com/kamadorueda/alejandra/issues/372#issuecomment-1435083516
{
outputs = {
outputs =
{
utils,
}:
# For each supported platform,
utils.lib.eachDefaultSystem (system: { });
utils.lib.eachDefaultSystem (system: { })
;
}
]
4 changes: 2 additions & 2 deletions test/diff/attr_set/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@

c = 1;

# d
# d

e = 1;

# f
# f

}
]
12 changes: 6 additions & 6 deletions test/diff/comment/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,25 @@
a = 1; # 3
b = 1;
c = 1; # 4
#5
#5

#6
#6

d = 1;
#7
#7
}

(let # 1
#2
a = 1; # 3
b = 1;
c = 1; # 4
#5
#5

#6
#6

d = 1;
#7
#7
in
d
)
Expand Down
3 changes: 2 additions & 1 deletion test/diff/idioms_lib_1/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
if pred then
trace msg x
else
x;
x
;
}
Loading

0 comments on commit e9cdac6

Please sign in to comment.