[Macros] Accessing the "parent context" of a syntax node passed to a macro

Here's a use case:

I have a theoretically-working prototype* of a macro that prints the enclosing context for logging. For instance, if you had

func myMethod(_ text: String, num: Int, flag: Bool) {
     #debugLog("message")
}

The macro would expand to printing myMethod("text", num: 4, flag: true): message to the console, or whatever the actual values of the parameters were.

To achieve this, you naturally need to be able to access the syntax of the parent declaration. This API provides that. I don't really have a critique on the proposed API — seems good to me.

*As in, I have done the SwiftSyntax manipulation logic already ... I just haven't bothered downloading a toolchain to actually make the macro yet.

7 Likes