Truth in advertising: I know zip about the compile...
# compiler
p
Truth in advertising: I know zip about the compiler but I want and need to know a lot more. My goal is to learn enough about the compiler to work on a Kotlin LSP server and do useful things. I could tell you more but you'd likely die of boredom if I elaborated. Please excuse my abuse/misuse of terminology as I learn and do direct me to code/documentation/etc so I can ask better questions. So here's the most direct question I can come up with: if I have a callable reference node (PsiElement), is there a way I can access the associated declaration at the time I see the reference node? I'm guessing that I can since the compiler must know about a declaration before it can label an identifier as a callable reference. The callable reference is a "println" in case it matters.
r
Hi Paul, it depends on which compiler phase you are on. If you are referring to accessing the type information or declaration descriptors associated to the PSI element, those become available after the Analysis phase. Phases are stages of the compilation process or hooks into the compiler, something you can wire with a compiler plugin (non officially supported yet). There you have the binding context and trace which you can use to iterate over the map of associated psi and descriptor elements and some compiler utils to get to whatever info you are after. FIR (the new upcoming frontend) may change those apis and they are considered compiler internal.
p
Excellent response. Thanks.
👍 1