I'm a little lost on something, perhaps someone can point me in the right direction.
I've created a new DeclarationMacro that constructs a new type say, "struct Foo".
A great example where this seems to have been achieved is in the new #Preview macro which both generates a new type, and adds its own Preview conformance too.
So, in the world of Swift, there's this thing called the inheritanceClause property inside StructDeclSyntax. I believe it could pretty good fit for your case. It's basically adding conforms to some protocol in your new declaration.
Here's a little Swift code to show you what I mean. Let's say you've got a struct Foo and you want it to play nice with a protocol Fooable:
public static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
[
DeclSyntax(
StructDeclSyntax(
identifier: .identifier("Foo"),
inheritanceClause: TypeInheritanceClauseSyntax {
InheritedTypeSyntax(
typeName: SimpleTypeIdentifierSyntax(
name: .identifier("Fooable")
)
)
},
memberBlockBuilder: {
// Members...
}
)
)
]
}
This is a proof of concept and more about learning Macro's, so there's some hard-coded values like "ContentView" which I know to exist ofc.
Also, note this isn't trying to backport much more than the syntactic sugar and convenience that #Preview provides since much of the implementation I think is baked into Xcode