How to access the outermost type name in a PeerMacro?

Hello everyone,

I am currently developing a Swift macro where I can retrieve the name of the outermost type (as a string) in a MemberMacro. However, I also need to access and use this type name in a PeerMacro.

For example:

class MyType {
    // In the `PeerMacro`, I need to access "MyType"
}

I would like to ask if there is a way to directly get the outermost type name in a PeerMacro, or if there’s a recommended method to pass the type name obtained in the MemberMacro to the PeerMacro?

Thanks in advance for any suggestions or help!

Sounds like lexicalContext introduced in [Macros] Accessing the "parent context" of a syntax node passed to a macro - #26 by Douglas_Gregor works for your use case

2 Likes