From ca1fe3572ea6134551ee6af40ae735a1a1ed0d35 Mon Sep 17 00:00:00 2001 From: piegames Date: Thu, 8 Feb 2024 15:34:13 +0100 Subject: [PATCH] Maybe fix --- src/Nixfmt/Pretty.hs | 18 +++++++++++------- test/diff/apply/out.nix | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index e43c6ed6..27640514 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -169,8 +169,11 @@ prettyTerm (List (Ann pre paropen post) items parclose) = prettyTerm (Set krec paropen items parclose) = prettySet False (krec, paropen, items, parclose) -- Parentheses -prettyTerm (Parenthesized paropen expr parclose) - = group $ pretty (moveTrailingCommentUp paropen) <> nest inner <> pretty parclose +prettyTerm (Parenthesized paropen expr (Ann closePre parclose closePost)) + = group $ + pretty (moveTrailingCommentUp paropen) + <> nest (inner <> pretty closePre) + <> pretty (Ann [] parclose closePost) where inner = case expr of @@ -345,15 +348,16 @@ prettyApp indentFunction pre hasPost f a pretty open <> pretty fn <> hardspace <> prettyTermWide body <> pretty close - absorbLast (Term (Parenthesized (Ann pre' open post') expr close)) + absorbLast (Term (Parenthesized (Ann pre' open post') expr (Ann pre'' close post''))) = group' Priority $ nest $ pretty (Ann pre' open Nothing) -- Move any trailing comments on the opening parenthesis down into the body - <> (surroundWith line' $ group $ nest $ - mapFirstToken + <> (surroundWith line' $ group' RegularG $ nest $ + pretty (mapFirstToken (\(Ann leading token trailing') -> (Ann (maybeToList (toLineComment <$> post') ++ leading) token trailing')) - expr + expr) + <> pretty pre'' ) - <> pretty close + <> pretty (Ann [] close post'') absorbLast arg = group' RegularG $ nest $ pretty arg -- Extract comment before the first function and move it out, to prevent functions being force-expanded diff --git a/test/diff/apply/out.nix b/test/diff/apply/out.nix index 4c63641c..590f9634 100644 --- a/test/diff/apply/out.nix +++ b/test/diff/apply/out.nix @@ -345,6 +345,6 @@ } (function ( something - # ... - ) { }) + # ... + ) { }) ]