Is there a way to get the original source-code fro...
# compiler
a
Is there a way to get the original source-code from an IrFile instance? I know you can load it from the fileEntry path (e.g. Kapshot does that) but doing file-io inside of a IrGenerationExtension seems to be clunky and risky (e.g. what if the IrGenerationExtension is being called inside of a tiny incremental recompile that should take single-digit milliseconds).
d
You can try the following:
Copy code
(irFile.metadata as? FirMetadataSource.File)
    ?.fir
    ?.source
    ?.getElementTextInContextForDebug()
👀 1
a
Interesting! Its neat that I can just go into the frontend IR like that. Unfortunately I just get null because my
irFile.metadata
is a
DescriptorMetadataSource.File
. Anything I can do from there?
Hum...
irFile.getKtFile()?.text
seems to be working. Does that do IO in the background or is the stuff in there already loaded?
d
It's already loaded
a
Any problems or caveats with doing it this way?
d
Nothing comes to mind