Skip to content

Commit

Permalink
Always preserve expanded attribute parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Jul 19, 2024
1 parent dfc5697 commit 6f7c153
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ instance Pretty Parameter where
-- param:
pretty (IDParameter i) = pretty i
-- {}:
pretty (SetParameter bopen [] bclose) =
group $ pretty (moveTrailingCommentUp bopen) <> hardspace <> pretty bclose
pretty (SetParameter bopen@Ann{sourceLine = openLine} [] bclose@Ann{sourceLine = closeLine}) =
group $ pretty (moveTrailingCommentUp bopen) <> (if openLine /= closeLine then hardline else hardspace) <> pretty bclose
-- { stuff }:
pretty (SetParameter bopen attrs bclose) =
pretty (SetParameter bopen@Ann{sourceLine = openLine} attrs bclose@Ann{sourceLine = closeLine}) =
group $
pretty (moveTrailingCommentUp bopen)
<> surroundWith sep (nest $ sepBy sep $ handleTrailingComma $ map moveParamAttrComment $ moveParamsComments attrs)
Expand All @@ -376,14 +376,17 @@ instance Pretty Parameter where
[pretty (ParamAttr name maybeDefault Nothing) <> trailing ","]
handleTrailingComma (x : xs) = pretty x : handleTrailingComma xs

sep = case attrs of
[ParamEllipsis _] -> line
-- Attributes must be without default
[ParamAttr _ Nothing _] -> line
[ParamAttr _ Nothing _, ParamEllipsis _] -> line
[ParamAttr _ Nothing _, ParamAttr _ Nothing _] -> line
[ParamAttr _ Nothing _, ParamAttr _ Nothing _, ParamEllipsis _] -> line
_ -> hardline
sep =
if openLine /= closeLine
then hardline
else case attrs of
[ParamEllipsis _] -> line
-- Attributes must be without default
[ParamAttr _ Nothing _] -> line
[ParamAttr _ Nothing _, ParamEllipsis _] -> line
[ParamAttr _ Nothing _, ParamAttr _ Nothing _] -> line
[ParamAttr _ Nothing _, ParamAttr _ Nothing _, ParamEllipsis _] -> line
_ -> hardline
pretty (ContextParameter param1 at param2) =
pretty param1 <> pretty at <> pretty param2

Expand Down

0 comments on commit 6f7c153

Please sign in to comment.