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 13530be commit 184104b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
22 changes: 16 additions & 6 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -231,27 +231,37 @@ prettyTerm (Selection term selectors rest) =
prettyTerm
( List
paropen@Ann
{ trailComment = Nothing
{ sourceLine = openLine,
trailComment = Nothing
}
(Items [])
parclose@Ann
{ preTrivia = []
{ sourceLine = closeLine,
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 openLine /= closeLine then hardline else hardspace
-- General list
-- Always expand if len > 1
prettyTerm
( List
paropen@Ann
{ trailComment = post
{ sourceLine = openLine,
trailComment = post
}
items
parclose
parclose@Ann
{ sourceLine = closeLine
}
) =
pretty (paropen{trailComment = Nothing})
<> surroundWith line (nest $ pretty post <> prettyItems items)
<> surroundWith sur (nest $ pretty post <> prettyItems items)
<> pretty parclose
where
sur = if openLine /= closeLine 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 184104b

Please sign in to comment.