Intellij plugin for Kotlin script definitions

I’m trying to make a plugin to add a custom script definition to IDEA. I’ve managed to make a script definition show up without any plugins if I have the project that contains the script definition loaded, but I’d like a more permanent solution. Right now I have the script definition

package dev.fishies.cohoplugin

import kotlin.script.experimental.annotations.KotlinScript
import kotlin.script.experimental.api.ScriptAcceptedLocation
import kotlin.script.experimental.api.ScriptCompilationConfiguration
import kotlin.script.experimental.api.acceptedLocations
import kotlin.script.experimental.api.ide
import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
import kotlin.script.experimental.jvm.jvm

@KotlinScript(
    displayName = "Coho script", fileExtension = "coho.kts", compilationConfiguration = CohoScriptConfiguration::class
)
abstract class CohoScript

object CohoScriptConfiguration : ScriptCompilationConfiguration({
    jvm {
        dependenciesFromCurrentContext(wholeClasspath = true)
    }
    ide {
        acceptedLocations(ScriptAcceptedLocation.Everywhere)
    }
})

and I also have put an empty file named dev.fishies.cohoplugin.CohoScript.classname in src/main/resources/META-INF/kotlin/script/templates/, but alas, it doesn’t show up in the IDE even when I have the plugin loaded:

It does, however, show up in the IDE window where I’m developing the plugin:

What am I doing wrong? Do the plugins not get automatically added to the classpath of the editor or something?

You can find the source code for the plugin here ↓

Also, looking towards the future, I’d like this script definition to inherit the classpath of another project of mine (coho), but right now I just want literally anything to work.

1 Like

We also use custom script definitions at work, but its not related to any plugin. The definitions are picked up by IntelliJ when we declare our scripting library as a dependency of the project that we are developing.

I guess you want the definition to be available in any IntelliJ project you are opening?

To me it feels like the scripting support in IntelliJ is not yet completely stable. We sometimes need to go through several steps of Maven clean install, project reload, invalidate cache + restart and alike to pick up updates of our script definition. But it got much better in the last two years!

Like I said before, the script definition works fine in the project that contains it. However, I want the script definition to show up in projects where I don’t have it open and it seemed like a plugin was the only way to do that, since it seems I can’t manually add script definitions to a classpath.