Skip to content

Commit 982bb09

Browse files
committed
[Macros] Only operator-fold attribute syntax for attached macro
This change restores the previous behavior changed by a8472a9. When expanding attached macros, macro implementation should only see the macro attribute syntax is operator folded, other syntax nodes - node, parentDeclNode, extendedType, and conformanceList - should not be operator-folded. rdar://162208759
1 parent 8ea19b6 commit 982bb09

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Sources/SwiftCompilerPluginMessageHandling/Macros.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,26 @@ extension PluginProviderMessageHandler {
149149
let swiftVersion = staticBuildConfiguration?.parserSwiftVersion
150150
let experimentalFeatures = staticBuildConfiguration?.experimentalFeatures
151151

152-
func addToSourceManager(_ syntax: PluginMessage.Syntax) -> Syntax {
152+
func addToSourceManager(_ syntax: PluginMessage.Syntax, foldOperators: Bool) -> Syntax {
153153
sourceManager.add(
154154
syntax,
155155
swiftVersion: swiftVersion,
156156
experimentalFeatures: experimentalFeatures,
157-
foldingWith: .standardOperators
157+
foldingWith: foldOperators ? .standardOperators : nil
158158
)
159159
}
160160

161-
let attributeNode = addToSourceManager(attributeSyntax)
161+
let attributeNode = addToSourceManager(attributeSyntax, foldOperators: true)
162162
.cast(AttributeSyntax.self)
163-
let declarationNode = addToSourceManager(declSyntax)
164-
let parentDeclNode = parentDeclSyntax.map { addToSourceManager($0).cast(DeclSyntax.self) }
163+
let declarationNode = addToSourceManager(declSyntax, foldOperators: false)
164+
let parentDeclNode = parentDeclSyntax.map {
165+
addToSourceManager($0, foldOperators: false).cast(DeclSyntax.self)
166+
}
165167
let extendedType = extendedTypeSyntax.map {
166-
addToSourceManager($0).cast(TypeSyntax.self)
168+
addToSourceManager($0, foldOperators: false).cast(TypeSyntax.self)
167169
}
168170
let conformanceList = conformanceListSyntax.map {
169-
let placeholderStruct = addToSourceManager($0).cast(StructDeclSyntax.self)
171+
let placeholderStruct = addToSourceManager($0, foldOperators: false).cast(StructDeclSyntax.self)
170172
return placeholderStruct.inheritanceClause!.inheritedTypes
171173
}
172174

0 commit comments

Comments
 (0)