Skip to content

Commit

Permalink
Always preserve expanded lists
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Jul 19, 2024
1 parent 7046daf commit e81d7d0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,19 @@ prettyTerm (Selection term selectors rest) =

-- Empty list
prettyTerm (List paropen@Ann{trailComment = Nothing} (Items []) parclose@Ann{preTrivia = []}) =
pretty paropen <> hardspace <> pretty parclose
pretty paropen <> sep <> pretty parclose
where
-- If the brackets are on different lines, keep them like that
sep = if sourceLine paropen /= sourceLine parclose then hardline else hardspace
-- General list
-- Always expand if len > 1
prettyTerm (List paropen@Ann{trailComment = post} items parclose) =
pretty (paropen{trailComment = Nothing})
<> surroundWith line (nest $ pretty post <> prettyItems items)
<> surroundWith sur (nest $ pretty post <> prettyItems items)
<> pretty parclose
where
-- If the brackets are on different lines, keep them like that
sur = if sourceLine paropen /= sourceLine parclose then hardline else line
prettyTerm (Set krec paropen items parclose) = prettySet False (krec, paropen, items, parclose)
-- Parentheses
prettyTerm (Parenthesized paropen expr parclose@Ann{preTrivia = closePre}) =
Expand Down
4 changes: 3 additions & 1 deletion test/diff/idioms_pkgs_3/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ buildStdenv.mkDerivation ({

inherit src unpackPhase meta;

outputs = [ "out" ] ++ lib.optionals crashreporterSupport [ "symbols" ];
outputs = [
"out"
] ++ lib.optionals crashreporterSupport [ "symbols" ];

# Add another configure-build-profiling run before the final configure phase if we build with pgo
preConfigurePhases = lib.optionals pgoSupport [
Expand Down
8 changes: 6 additions & 2 deletions test/diff/idioms_pkgs_4/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ let
]
++ (
if system == "i686-cygwin" then
[ ../cygwin/rebase-i686.sh ]
[
../cygwin/rebase-i686.sh
]
else if system == "x86_64-cygwin" then
[ ../cygwin/rebase-x86_64.sh ]
[
../cygwin/rebase-x86_64.sh
]
else
[ ]
);
Expand Down
4 changes: 3 additions & 1 deletion test/diff/lists/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
]
[ 1 ]

[ 1 ]
[
1
]

[
b
Expand Down
4 changes: 3 additions & 1 deletion test/diff/operation/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@
zip
zlib
]
++ [ (if (lib.versionAtLeast version "103") then nss_latest else nss_esr) ]
++ [
(if (lib.versionAtLeast version "103") then nss_latest else nss_esr)
]
)

# Indentation with parenthesized multiline function call
Expand Down

0 comments on commit e81d7d0

Please sign in to comment.