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
8 changes: 6 additions & 2 deletions Sources/SwiftCompilerPluginMessageHandling/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import SwiftBasicFormat
import SwiftDiagnostics
import SwiftOperators
import SwiftSyntax
import SwiftSyntaxMacros

Expand All @@ -28,7 +29,7 @@ extension CompilerPluginMessageHandler {
expandingSyntax: PluginMessage.Syntax
) throws {
let sourceManager = SourceManager()
let syntax = sourceManager.add(expandingSyntax)
let syntax = sourceManager.add(expandingSyntax, foldingWith: .standardOperators)

let context = PluginMacroExpansionContext(
sourceManager: sourceManager,
Expand Down Expand Up @@ -97,7 +98,10 @@ extension CompilerPluginMessageHandler {
expansionDiscriminator: discriminator
)

let attributeNode = sourceManager.add(attributeSyntax).cast(AttributeSyntax.self)
let attributeNode = sourceManager.add(
attributeSyntax,
foldingWith: .standardOperators
).cast(AttributeSyntax.self)
let declarationNode = sourceManager.add(declSyntax).cast(DeclSyntax.self)

let expandedSources: [String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ class SourceManager {

/// Convert syntax information to a `Syntax` node. The location informations
/// are cached in the source manager to provide `location(of:)` et al.
func add(_ syntaxInfo: PluginMessage.Syntax) -> Syntax {
func add(
_ syntaxInfo: PluginMessage.Syntax,
foldingWith operatorTable: OperatorTable? = nil
) -> Syntax {

var node: Syntax
var parser = Parser(syntaxInfo.source)
Expand All @@ -82,7 +85,9 @@ class SourceManager {
case .attribute:
node = Syntax(AttributeSyntax.parse(from: &parser))
}
node = OperatorTable.standardOperators.foldAll(node, errorHandler: { _ in /*ignore*/ })
if let operatorTable = operatorTable {
node = operatorTable.foldAll(node, errorHandler: { _ in /*ignore*/ })
}

// Copy the location info from the plugin message.
let location = KnownSourceSyntax.Location(
Expand Down