@@ -271,7 +271,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
271271 // `arrange*` functions here.
272272 before ( node. firstToken ( viewMode: . sourceAccurate) , tokens: . open)
273273
274- arrangeAttributeList ( node. attributes)
274+ arrangeAttributeList ( node. attributes, separateByLineBreaks : config . lineBreakBeforeEachArgument )
275275
276276 let hasArguments = !node. signature. parameterClause. parameters. isEmpty
277277
@@ -326,7 +326,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
326326 ) {
327327 before ( node. firstToken ( viewMode: . sourceAccurate) , tokens: . open)
328328
329- arrangeAttributeList ( attributes)
329+ arrangeAttributeList ( attributes, separateByLineBreaks : config . lineBreakBetweenDeclarationAttributes )
330330
331331 // Prioritize keeping "<modifiers> <keyword> <name>:" together (corresponding group close is
332332 // below at `lastTokenBeforeBrace`).
@@ -458,7 +458,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
458458 after ( node. returnClause. lastToken ( viewMode: . sourceAccurate) , tokens: . close)
459459 }
460460
461- arrangeAttributeList ( node. attributes)
461+ arrangeAttributeList ( node. attributes, separateByLineBreaks : config . lineBreakBetweenDeclarationAttributes )
462462
463463 if let genericWhereClause = node. genericWhereClause {
464464 before ( genericWhereClause. firstToken ( viewMode: . sourceAccurate) , tokens: . break( . same) , . open)
@@ -513,7 +513,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
513513 ) where BodyContents. Element: SyntaxProtocol {
514514 before ( node. firstToken ( viewMode: . sourceAccurate) , tokens: . open)
515515
516- arrangeAttributeList ( attributes)
516+ arrangeAttributeList ( attributes, separateByLineBreaks : config . lineBreakBetweenDeclarationAttributes )
517517 arrangeBracesAndContents ( of: body, contentsKeyPath: bodyContentsKeyPath)
518518
519519 if let genericWhereClause = genericWhereClause {
@@ -549,7 +549,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
549549 }
550550
551551 override func visit( _ node: AccessorDeclSyntax ) -> SyntaxVisitorContinueKind {
552- arrangeAttributeList ( node. attributes)
552+ arrangeAttributeList ( node. attributes, separateByLineBreaks : config . lineBreakBetweenDeclarationAttributes )
553553 arrangeBracesAndContents ( of: node. body, contentsKeyPath: \. statements)
554554 return . visitChildren
555555 }
@@ -1327,7 +1327,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
13271327 }
13281328
13291329 override func visit( _ node: MacroExpansionDeclSyntax ) -> SyntaxVisitorContinueKind {
1330- arrangeAttributeList ( node. attributes)
1330+ arrangeAttributeList ( node. attributes, separateByLineBreaks : config . lineBreakBetweenDeclarationAttributes )
13311331
13321332 before (
13331333 node. trailingClosure? . leftBrace,
@@ -1546,7 +1546,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
15461546 override func visit( _ node: EnumCaseDeclSyntax ) -> SyntaxVisitorContinueKind {
15471547 before ( node. firstToken ( viewMode: . sourceAccurate) , tokens: . open)
15481548
1549- arrangeAttributeList ( node. attributes)
1549+ arrangeAttributeList ( node. attributes, separateByLineBreaks : config . lineBreakBetweenDeclarationAttributes )
15501550
15511551 after ( node. caseKeyword, tokens: . break)
15521552 after ( node. lastToken ( viewMode: . sourceAccurate) , tokens: . close)
@@ -2179,7 +2179,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
21792179 }
21802180
21812181 override func visit( _ node: VariableDeclSyntax ) -> SyntaxVisitorContinueKind {
2182- arrangeAttributeList ( node. attributes)
2182+ arrangeAttributeList ( node. attributes, separateByLineBreaks : config . lineBreakBetweenDeclarationAttributes )
21832183
21842184 if node. bindings. count == 1 {
21852185 // If there is only a single binding, don't allow a break between the `let/var` keyword and
@@ -2285,7 +2285,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
22852285 }
22862286
22872287 override func visit( _ node: TypeAliasDeclSyntax ) -> SyntaxVisitorContinueKind {
2288- arrangeAttributeList ( node. attributes)
2288+ arrangeAttributeList ( node. attributes, separateByLineBreaks : config . lineBreakBetweenDeclarationAttributes )
22892289
22902290 after ( node. typealiasKeyword, tokens: . break)
22912291
@@ -2499,7 +2499,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
24992499 }
25002500
25012501 override func visit( _ node: AssociatedTypeDeclSyntax ) -> SyntaxVisitorContinueKind {
2502- arrangeAttributeList ( node. attributes)
2502+ arrangeAttributeList ( node. attributes, separateByLineBreaks : config . lineBreakBetweenDeclarationAttributes )
25032503
25042504 after ( node. associatedtypeKeyword, tokens: . break)
25052505
@@ -2890,14 +2890,30 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
28902890 /// Applies formatting tokens around and between the attributes in an attribute list.
28912891 private func arrangeAttributeList(
28922892 _ attributes: AttributeListSyntax ? ,
2893- suppressFinalBreak: Bool = false
2893+ suppressFinalBreak: Bool = false ,
2894+ separateByLineBreaks: Bool = false
28942895 ) {
28952896 if let attributes = attributes {
2897+ let behavior : NewlineBehavior = separateByLineBreaks ? . hard : . elective
28962898 before ( attributes. firstToken ( viewMode: . sourceAccurate) , tokens: . open)
2897- insertTokens ( . break( . same) , betweenElementsOf: attributes)
2899+ for element in attributes. dropLast ( ) {
2900+ if let ifConfig = element. as ( IfConfigDeclSyntax . self) {
2901+ for clause in ifConfig. clauses {
2902+ if let nestedAttributes = AttributeListSyntax ( clause. elements) {
2903+ arrangeAttributeList (
2904+ nestedAttributes,
2905+ suppressFinalBreak: true ,
2906+ separateByLineBreaks: separateByLineBreaks
2907+ )
2908+ }
2909+ }
2910+ } else {
2911+ after ( element. lastToken ( viewMode: . sourceAccurate) , tokens: . break( . same, newlines: behavior) )
2912+ }
2913+ }
28982914 var afterAttributeTokens = [ Token . close]
28992915 if !suppressFinalBreak {
2900- afterAttributeTokens. append ( . break( . same) )
2916+ afterAttributeTokens. append ( . break( . same, newlines : behavior ) )
29012917 }
29022918 after ( attributes. lastToken ( viewMode: . sourceAccurate) , tokens: afterAttributeTokens)
29032919 }
0 commit comments