Hello! Are there any repos or examples of how to u...
# intellij-plugins
g
Hello! Are there any repos or examples of how to use Kotlin script engine in Intellij plugin dev? I’m trying to start with a simple code:
Copy code
setIdeaIoUseFallback()
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
I’ve added dependencies and
/services/javax.script.ScriptEngineFactory
file. But the engine is actually null. There is no factory for Kotlin in
Copy code
ScriptEngineManager().engineFactories
r
If you depend on the Kotlin plugin it provides a different factory for the script engine manager
org.jetbrains.kotlin.jsr223.KotlinJsr223JvmScriptEngine4Idea
The issue with this factory is that the first time you invoke it and tries to connect to the kotlin compiler daemon it calls Thread.stop and it blows up with a ThreadDeath exception.
@gammanik what does
setIdeaIoUseFallback()
do?
g
I guess I need to do something like this
Copy code
val clazz: Class<*> = Class.forName("org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine")
val factory: ScriptEngineFactory? = ScriptEngineManager(clazz.classLoader).getEngineByName("kotlin")?.factory
Copy code
ScriptEngineManager(clazz.classLoader)
Instead of empty construtor I get it from gere https://stackoverflow.com/questions/53055500/how-do-i-retrieve-kotlin-jsr223-script-engine-from-scriptenginemanager At least this way I can see the factory
setIdeaIoUseFallback() does nothing
thanks!
Copy code
KotlinJsr223StandardScriptEngineFactory4Idea()
Is working.