Hi. Is there currently any way to make IDE "see" c...
# scripting
Hi. Is there currently any way to make IDE "see" certain properties/functions as being available in script inside .kts file? To elaborate - when script is run with JSR-223, it will have
val bindings: Bindings
available in its context. However, when editing a .kts file there doesn't seem to be obvious way to inform IDE about that, short of writing
val bindings: Bindings = SimpleBindings()
at the beginning of the file and commenting it out before compiling.
Hi. You can use a ScriptTemplateDefinition. IntelliJ can use that to resolve references within the script as if it were an instance of the script template class. We do that here: https://github.com/apollo-rsps/apollo/blob/kotlin-experiments/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt and each of our .kts files ends up being a subclass of KotlinPluginScript
Currently you need to configure the classpath and the fully qualified class name in the kotlin settings window of the IDE, but there are changes in the 1.2.50 EAP that makes discovery easier
Moreover, in the new scripting API, available for preview starting from 1.2.50, it is possible to define external “environment” variables for scripts, and if appropriate script definition is imported into IDEA, these will be properly resolved too. It will eventually come into JSR 223 wrappers (definitely not in 1.2.50 though). It will be also a solution for related https://youtrack.jetbrains.com/issue/KT-15125. The only problem is that it is all not documented yet. But if you want to try it anyway, start with
modules and related samples/tests in the Kotlin project.
@ilya.chernikov Will 1.2.50 scripting support allow to import
file in
and get
class autocomplete from the
file ? Use case is
based configuration.
yes, it currently does allow that (and we are currently using this via the mechanism provided above). The changes in 1.2.50 make discovery of *.kts templates easier using a service discovery style loader.
@sdeleuze I’m not sure I understand your question completely, but you can have
files in one sourceset and reference one another. To use a script class from a regular
you’ll need to know how script class names are generated. What is new with 1.2.50 is that you may have custom scripts in your sourcesets, distinguished by an extension (still should end with
for a moment though) and automatically recognized by compiler and IDE using discovery mechanism, by just adding appropriate dependency to the project.
Thank you!