Hi there, for a Kotlin/JS app, I’d like to show sa...
# ksp
h
Hi there, for a Kotlin/JS app, I’d like to show sample code on a web page. This sample code is the body of a lambda (but could also be refactored to a normal function / method. Currently I copy/paste the sample code into a multi line string constant and use that constant to show the sample code on the web page. Is it possible to mark the function containing the sample code with an annotation and use a KSP processor to extract the function body and generate a string constant with that exact source code? Ot is this only possible using a compiler plugin?
g
It may be possible, if you have 1 annotation by file you can retrieve the containingFile of annotated symbols and generate a string from that, also KSP is more about the structure (symbols) than the code inside (runtime). You may be interested by Knit that is generating example files from a markdown documentation, if ever your website is generated from markdown.
👍 1
h
Thanks @Grégory Lureau!
j
Unfortunately, parsing function body is impossible for KSP.