Skip to content

Commit

Permalink
application: Special case list arguments 1/2
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Oct 3, 2024
1 parent 7c0a82c commit 5d52f90
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 60 deletions.
6 changes: 6 additions & 0 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ prettyApp indentFunction pre hasPost f a =
-- because if they get expanded before anything else,
-- only the `.`-and-after part gets to a new line, which looks very odd
absorbApp (Application f' a'@(Term Selection{})) = group' Transparent (absorbApp f') <> line <> nest (group' RegularG $ absorbInner a')
-- If two consecutive arguments are lists, treat them specially: Don't priority expand, and also
-- if one does not fit onto the line then put both on a new line each.
-- Note that this does not handle the case where the two last arguments are lists, as the last argument
-- is handled elsewhere and cannot be pattern-matched here.
absorbApp (Application (Application f' l1@(Term List{})) l2@(Term List{})) =
group' Transparent (group' Transparent (absorbApp f') <> nest (group' RegularG $ line <> group (absorbInner l1) <> line <> group (absorbInner l2)))
absorbApp (Application f' a') = group' Transparent (absorbApp f') <> line <> nest (group' Priority $ absorbInner a')
-- First argument
absorbApp expr
Expand Down
63 changes: 33 additions & 30 deletions test/diff/apply_with_lists/out-pure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
]
)
(replaceStrings [ ''"'' "\\" ] [ ''\"'' "\\\\" ] name)
(replaceStrings [ ''"'' "\\" ]
(replaceStrings
[ ''"'' "\\" ]
# force multiline
[ ''\"'' "\\\\" ]
name
Expand Down Expand Up @@ -46,20 +47,18 @@
1
2
] [ ])
(builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [
partitionTypes.usr-verity
] (builtins.readFile ./assert_uki_repart_match.py))
(builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [ partitionTypes.usr-verity ]
(builtins.readFile ./assert_uki_repart_match.py)
)
(replaceStrings [ "-" ] [ "_" ] (toUpper final.rust.cargoShortTarget))
(lib.mkChangedOptionModule [ "security" "acme" "validMin" ] [
"security"
"acme"
"defaults"
"validMinDays"
] (config: config.security.acme.validMin / (24 * 3600)))
(lib.replaceStrings [ "https://registry" ".io/providers" ] [
"registry"
".io"
] homepage)
(lib.mkChangedOptionModule
[ "security" "acme" "validMin" ]
[ "security" "acme" "defaults" "validMinDays" ]
(config: config.security.acme.validMin / (24 * 3600))
)
(lib.replaceStrings [ "https://registry" ".io/providers" ] [ "registry" ".io" ]
homepage
)
(lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [
"console"
"extraTTYs"
Expand Down Expand Up @@ -103,20 +102,24 @@
setupWorkDir
]
)
(lib.switch [ coq.coq-version ssreflect.version ] [
{
cases = [
(lib.versions.range "8.15" "8.20")
lib.pred.true
];
out = "2.0.4";
}
{
cases = [
"8.5"
lib.pred.true
];
out = "20170512";
}
] null)
(lib.switch
[ coq.coq-version ssreflect.version ]
[
{
cases = [
(lib.versions.range "8.15" "8.20")
lib.pred.true
];
out = "2.0.4";
}
{
cases = [
"8.5"
lib.pred.true
];
out = "20170512";
}
]
null
)
]
63 changes: 33 additions & 30 deletions test/diff/apply_with_lists/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
]
)
(replaceStrings [ ''"'' "\\" ] [ ''\"'' "\\\\" ] name)
(replaceStrings [ ''"'' "\\" ]
(replaceStrings
[ ''"'' "\\" ]
# force multiline
[ ''\"'' "\\\\" ]
name
Expand Down Expand Up @@ -46,20 +47,18 @@
1
2
] [ ])
(builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [
partitionTypes.usr-verity
] (builtins.readFile ./assert_uki_repart_match.py))
(builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [ partitionTypes.usr-verity ]
(builtins.readFile ./assert_uki_repart_match.py)
)
(replaceStrings [ "-" ] [ "_" ] (toUpper final.rust.cargoShortTarget))
(lib.mkChangedOptionModule [ "security" "acme" "validMin" ] [
"security"
"acme"
"defaults"
"validMinDays"
] (config: config.security.acme.validMin / (24 * 3600)))
(lib.replaceStrings [ "https://registry" ".io/providers" ] [
"registry"
".io"
] homepage)
(lib.mkChangedOptionModule
[ "security" "acme" "validMin" ]
[ "security" "acme" "defaults" "validMinDays" ]
(config: config.security.acme.validMin / (24 * 3600))
)
(lib.replaceStrings [ "https://registry" ".io/providers" ] [ "registry" ".io" ]
homepage
)
(lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [
"console"
"extraTTYs"
Expand Down Expand Up @@ -103,20 +102,24 @@
setupWorkDir
]
)
(lib.switch [ coq.coq-version ssreflect.version ] [
{
cases = [
(lib.versions.range "8.15" "8.20")
lib.pred.true
];
out = "2.0.4";
}
{
cases = [
"8.5"
lib.pred.true
];
out = "20170512";
}
] null)
(lib.switch
[ coq.coq-version ssreflect.version ]
[
{
cases = [
(lib.versions.range "8.15" "8.20")
lib.pred.true
];
out = "2.0.4";
}
{
cases = [
"8.5"
lib.pred.true
];
out = "20170512";
}
]
null
)
]

0 comments on commit 5d52f90

Please sign in to comment.