Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ instance Pretty Parameter where
group $
pretty (moveTrailingCommentUp bopen)
<> surroundWith sep (nest $ sepBy sep $ handleTrailingComma $ map moveParamAttrComment $ moveParamsComments attrs)
<> pretty bclose
<> nest (pretty (preTrivia bclose))
<> pretty (bclose{preTrivia = []})
Comment on lines -353 to +354
Copy link
Copy Markdown
Contributor

@MattSturgeon MattSturgeon Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand this diff, or why we need to handle bclose twice; passing it to nest and then handling it again with preTrivia overridden.

Is preTrivia the indentation? Or perhaps the # prefix of the comment? What's the reason we can't just nest the comment without handling it twice?

EDIT: is blcose the closing brace, and preTrivia its attached comments?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. So we're nesting the attached comments and formatting the rest of the token

where
-- pretty all ParamAttrs, but mark the trailing comma of the last element specially
-- This is so that the trailing comma will only be printed in the expanded form
Expand Down
35 changes: 35 additions & 0 deletions test/correct/commented-params-list.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
# param1,
param2,
# param3,
# param4,
param5,
# param6,
}:
{
# param7,
param8,
# param9,
/*
multiline comment
1
*/
# param10,
param11,
/*
multiline comment
2
*/
}:
{
param12,

# param13
}:
{
param13,

# param14

}:
{ }
2 changes: 1 addition & 1 deletion test/diff/monsters_1/out-pure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# foo
# foo
wrapGAppsHook4,
# foo
# foo
}:
# foo
stdenv.mkDerivation
Expand Down
2 changes: 1 addition & 1 deletion test/diff/monsters_1/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# foo
# foo
wrapGAppsHook4,
# foo
# foo
}:
# foo
stdenv.mkDerivation
Expand Down
4 changes: 2 additions & 2 deletions test/diff/pattern/out-pure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,8 @@
# g
#
...
# h
#
# h
#
}
# i
#
Expand Down
4 changes: 2 additions & 2 deletions test/diff/pattern/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,8 @@
# g
#
...
# h
#
# h
#
}
# i
#
Expand Down