From c002c55a91d4e0c89bd275943172b573103c2fa2 Mon Sep 17 00:00:00 2001 From: piegames Date: Sat, 17 Aug 2024 10:06:04 +0200 Subject: [PATCH] Experiment --- src/Nixfmt/Pretty.hs | 16 ++++++++++++++++ test/diff/apply/out.nix | 14 ++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index e52fb2a..acc8cc5 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -394,6 +394,22 @@ prettyApp indentFunction pre hasPost f a = where -- If the brackets are on different lines, keep them like that sur = if sourceLine paropen /= sourceLine parclose then hardline else line + -- Same for sets. Limit is two items + absorbInner (Term (Set krec paropen@Ann{trailComment = post'} binders parclose)) = + -- \| length (unItems binders) <= 2 && all isSimpleBinding binders = + pretty (fmap (,hardspace) krec) + <> pretty (paropen{trailComment = Nothing}) + <> surroundWith sep (nest $ pretty post' <> prettyItems binders) + <> pretty parclose + where + isSimpleBinding (Assignment sels (LoneAnn _) rhs (LoneAnn _)) = + all isSimpleSelector sels && isSimple rhs + isSimpleBinding _ = False + -- If the braces are on different lines, keep them like that + sep = + if sourceLine paropen /= sourceLine parclose + then line + else line absorbInner expr = pretty expr -- Render the last argument of a function call diff --git a/test/diff/apply/out.nix b/test/diff/apply/out.nix index 6692fd4..d053a4d 100644 --- a/test/diff/apply/out.nix +++ b/test/diff/apply/out.nix @@ -122,16 +122,10 @@ # multiline } argument; - name3 = - function arg - { - asdf = 1; - # multiline - } - { - qwer = 12345; - } - argument; + name3 = function arg { + asdf = 1; + # multiline + } { qwer = 12345; } argument; } { name4 = function arg { asdf = 1; } {