Slide 35
Slide 35 text
Testing, Debugging & Diagnostics
You can go even deeper with what’s called a Diagnostic, where you can customize
the severity, add fix-its, and even notes and highlights
enum AgendaMacroDiagnostic: String, DiagnosticMessage {
var message: String {
switch self {
case .tooAwesome:
"This lecture is awesome, it doesn't need an agenda!"
}
}
var diagnosticID: MessageID {
MessageID(domain: "com.freak4pc.app", id: rawValue)
}
var severity: DiagnosticSeverity {
switch self {
case .tooAwesome:
.warning
}
}
case tooAwesome
}
public struct AgendaMacro: MemberMacro {
public static func expansion(
of node: AttributeSyntax,
providingMembersOf declaration: some DeclGroupSyntax,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
// ..
context.diagnose(
Diagnostic(
node: node,
message: AgendaMacroDiagnostic.tooAwesome,
highlights: […],
notes: […],
fixIts: […]
)
)
return []