If I create my own kind of kotlin scripts, e.g. wi...
# scripting
t
If I create my own kind of kotlin scripts, e.g. with
Copy code
@KotlinScript(fileExtension = "my.kts")
abstract class MyScript
Presumably with some default imports and some implicit receivers, how do I get IntelliJ to help me highlight and autocomplete my file?
b
Not much else you can do other than praying.
t
Oh... is there a ticket or something I can follow?
b
Since there's no way to explicitly mark a file as kscript, it's up to IDE gods to decide if it'll be recognized
i
@Tianyu Zhu please have look at the example projects, e.g. here - https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/simple-main-kts/SimpleMainKts.md. In particular, you need to add a discovery file with the name
<FQN of your script definition>.classname
( e.g. like here https://github.com/Kotlin/kotlin-script-examples/tree/master/jvm/simple-main-kts/simple-main-kts/src/main/resources/META-INF/kotlin/script/templates) and then if you add the jar to a project dependencies, the script files will be automatically recognized in the source roots of that project.
t
🤯
All I had to do was to build the project, and now everything is highlighted!
And here are the script definitions loaded by IntelliJ!