I would like to use the Kotlin Analysis API compil...
# compiler
t
I would like to use the Kotlin Analysis API compiler to compile a file with a intellij plugin on the fly. https://kotlin.github.io/analysis-api/file-compilation.html Unfortunately there is not much documentation how to do that. I think i was able to provide the classpath but i want to provide compiler plugins as well. Not sure how to do that and if it is possible. At the end i just want to recompile a changed file before it is saved to disk. And i also want to execute a function. So i need to provide the compiled file to a classloader.
d
AFAIR there is no API to compile something with Analysis API cc @yan
y
@Timo Drick How did you configure the module with your file? In the Analysis API, there is indeed a
KaCompilerFacility
that can do the job, and it attaches compiler plugins provided via
KtCompilerPluginsProviderIdeImpl
. However, it currently only works with source modules, while your use-case seems to be creating a new in-memory file and providing classpath/plugins to it externally. Could you please explain the goal so we better understand the limits?
t
My specific use case is a intellij plugin that analyzes a kotlin multiplatform project. And show previews of composable functions. So i do have access to all the configuration. But i do not know how to provide this information to the analysis api. And i would like to compile the file which is open in an source code editor.
So i do have the file as psiFile and call analyze(psiFile)... And i want to compile this file when it changes. And only this file. I do already search for annotations using the kotlin analysis api and it works very well.