From 59e986d8f442a6cf7bc43cb91602151c2bd9942e 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 | 6 +++++- test/correct/regression-207.nix | 5 +++++ 2 files changed, 10 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..83b02afb 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -375,7 +375,11 @@ 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; +}