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 1510f5e
Show file tree
Hide file tree
Showing 16 changed files with 812 additions and 643 deletions.
23 changes: 19 additions & 4 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,26 @@ instance Pretty Binder where
= base $ group (pretty inherit <> hardspace
<> nest 2 ((pretty source) <> line <> sepBy line ids <> line' <> pretty semicolon))

-- `foo = bar`
-- `foo = bar`, where bar is a function declaration
pretty (Assignment selectors assign expr@(Abstraction _ _ _) semicolon)
= base $ group $ hcat selectors <> hardspace
<> nest 2 (pretty assign <> group (line <> pretty expr <> line' <> pretty semicolon))

-- `foo = bar`, where bar is a let binding
pretty (Assignment selectors assign expr@(Let _ _ _ _) semicolon)
= base $ group $ hcat selectors <> hardspace
<> nest 2 (pretty assign <> line <> pretty expr <> line' <> pretty semicolon)

-- `foo = bar`, where bar is an absorbable expression (list/attrset)
pretty (Assignment selectors assign expr@(Term t) semicolon) | isAbsorbable t
= base $ group $ hcat selectors <> hardspace
<> nest 2 (pretty assign <> hardspace <> group expr <> softline' <> pretty semicolon)

-- `foo = bar`, otherwise
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 <> 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 1510f5e

Please sign in to comment.