Skip to content

Commit

Permalink
Maybe fix
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Feb 8, 2024
1 parent d1951b5 commit ca1fe35
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/diff/apply/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,6 @@
}
(function (
something
# ...
) { })
# ...
) { })
]

0 comments on commit ca1fe35

Please sign in to comment.