From e39b2fae3aad9fc64288cb73b29a0d913f94ce4a Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 30 Aug 2024 01:50:18 +0200 Subject: [PATCH] Fix selections getting expanded too liberally --- src/Nixfmt/Pretty.hs | 7 ++++++- test/correct/regression-207.nix | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/correct/regression-207.nix diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index 120ef92b..504cd75d 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -375,7 +375,12 @@ instance Pretty Parameter where -- then start on a new line instead". prettyApp :: Bool -> Doc -> Bool -> Expression -> Expression -> Doc prettyApp indentFunction pre hasPost f a = - let absorbApp (Application f' a') = group' Transparent (absorbApp f') <> line <> nest (group' Priority a') + let + -- This is very hacky, but selections shouldn't be in a priority group, + -- 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 a') + absorbApp (Application f' a') = group' Transparent (absorbApp f') <> line <> nest (group' Priority a') absorbApp expr | indentFunction && null comment' = nest $ group' RegularG $ line' <> pretty expr | otherwise = pretty expr diff --git a/test/correct/regression-207.nix b/test/correct/regression-207.nix new file mode 100644 index 00000000..3213e9e7 --- /dev/null +++ b/test/correct/regression-207.nix @@ -0,0 +1,5 @@ +{ + rust-channel-of-version = + assertEq (rustChannelOf { channel = "1.48.0"; }).rustc + stable."1.48.0".rustc; +}