MacroExpansionContext
Interface to extract information about the context in which a given macro is expanded.
protocol MacroExpansionContext : AnyObject
Browse conforming typesInterface to extract information about the context in which a given macro is expanded.
protocol MacroExpansionContext : AnyObject
import SwiftSyntaxMacros
var lexicalContext: [Syntax] { get }
Return an array of enclosing lexical contexts for the purpose of macros, starting from the syntax node at which the macro expansion occurs and containing all “context” nodes including functions, closures, types, properties, subscripts, and extensions.
func diagnose(_ diagnostic: Diagnostic)
Produce a diagnostic while expanding the macro.
func location(of node: some SyntaxProtocol, at position: PositionInSyntaxNode, filePathMode: SourceLocationFilePathMode) -> AbstractSourceLocation?
Retrieve a source location for the given syntax node.
func makeUniqueName(_ name: String) -> TokenSyntax
Generate a unique name for use in the macro.
func addDiagnostics(from error: Error, node: some SyntaxProtocol)
Adds diagnostics from the error thrown during a macro expansion.
func location(of node: some SyntaxProtocol) -> AbstractSourceLocation?
Retrieve a source location for the given syntax node’s starting token (after leading trivia) using file naming according to #fileID
.
var lexicalContext: [Syntax] { get }