Skip to content

Commit

Permalink
fixup! application: Special case list arguments 2/2
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Oct 14, 2024
1 parent f10535d commit 1638141
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
19 changes: 12 additions & 7 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,18 @@ prettyApp indentFunction pre hasPost f a =

post = if hasPost then line' else mempty
in pretty comment'
<> case (f, a) of
-- When the two last arguments are lists, don't absorb the last one (absorbLast)
(Application _ (Term List{}), Term List{}) ->
renderSimple
(absorbApp (Application fWithoutComment a))
(\fRendered -> group' RegularG fRendered)
(\fRendered -> group' RegularG $ fRendered <> post)
<> case (fWithoutComment, a) of
-- When the two last arguments are lists, render these specially (same as above)
-- Also no need to wrap in renderSimple here, because we know that these kinds of arguments
-- are never "simple" by definition.
(Application fWithoutCommandAndWithoutArg l1@(Term List{}), l2@(Term List{})) ->
group' RegularG $
(pre <> group' Transparent (absorbApp fWithoutCommandAndWithoutArg))
<> line
<> nest (group (absorbInner l1))
<> line
<> nest (group (absorbInner l2))
<> post
_ ->
renderSimple
(absorbApp fWithoutComment)
Expand Down
8 changes: 6 additions & 2 deletions test/diff/apply_with_lists/out-pure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
)
(lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ "console" "extraTTYs" ])
# This line is engineered to exactly hit the line length limit
(lib.mkRenamedOptionModule [ "hardware" "package234" ] [ "hardware" "graphics" ]
(lib.mkRenamedOptionModule
[ "hardware" "package234" ]
[ "hardware" "graphics" ]
)
(mkRenamedOptionModule
[
Expand Down Expand Up @@ -102,7 +104,9 @@
[ "Blue" "Flamingo" "Green" ]
[ accent ]
lib.checkListOfEnum
"${pname}: color variant" [ "Latte" "Frappe" "Macchiato" "Mocha" ] [ variant ]
"${pname}: color variant"
[ "Latte" "Frappe" "Macchiato" "Mocha" ]
[ variant ]
)
(lib.switch
[ coq.coq-version ssreflect.version ]
Expand Down
8 changes: 6 additions & 2 deletions test/diff/apply_with_lists/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
)
(lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ "console" "extraTTYs" ])
# This line is engineered to exactly hit the line length limit
(lib.mkRenamedOptionModule [ "hardware" "package234" ] [ "hardware" "graphics" ]
(lib.mkRenamedOptionModule
[ "hardware" "package234" ]
[ "hardware" "graphics" ]
)
(mkRenamedOptionModule
[
Expand Down Expand Up @@ -106,7 +108,9 @@
]
[ accent ]
lib.checkListOfEnum
"${pname}: color variant" [ "Latte" "Frappe" "Macchiato" "Mocha" ] [ variant ]
"${pname}: color variant"
[ "Latte" "Frappe" "Macchiato" "Mocha" ]
[ variant ]
)
(lib.switch
[ coq.coq-version ssreflect.version ]
Expand Down

0 comments on commit 1638141

Please sign in to comment.