Hello Scripters! With moving my own DSL project to...
# scripting
o
Hello Scripters! With moving my own DSL project to Kotlin 2.1 (coming from 1.9), I experience some problems with the tooling setup, specifically with IntelliJ offering syntax highlight and code completion on my own script files with their own extension. It used to work like this: In my DSL library project, there is a class with a
@KotlinScript
annotation like this:
Copy code
const val TRALA_FILE_EXTENSION = "trala.kts"

@KotlinScript(
    displayName = "TraLa Script",
    fileExtension = TRALA_FILE_EXTENSION,
    compilationConfiguration = TraLaScriptConfiguration::class
)
abstract class TraLaScript
plus, there is a resource file at this location:
resources/META-INF/kotlin/script/templates/com.bmw.transformation.scripting.TraLaScript
(which is empty) The compilation configuration looks like this:
Copy code
@Suppress("JavaIoSerializableObjectMustHaveReadResolve")
object TraLaScriptConfiguration : ScriptCompilationConfiguration(
    {
        defaultImports(traLaDefaultImports)

        ide {
            acceptedLocations(ScriptAcceptedLocation.Everywhere)
        }

        jvm {
            jvmTarget("17")
            compilerOptions("-Xcontext-receivers")
        }
    }
)
The idea is that any project that uses my DSL library can have files anywhere (see
acceptedLocations
with the extension
.trala.kts
and the editor will offer syntax highlight and code completion / inspection. This used to work. Sometimes I had to restart IntelliJ... it was never straight forward. But it worked. Now, I cannot see any way to make the editor behave like I want. And I do not know what changed. In projects that DEPEND on my lib (with this setup), nothing works any more. In my library project itself, the default imports don't seem to work anymore! When I add a new file
foo.trala.kts
and start typing code, it inserts import statements that it should not, because they are part of the default imports... What am I doing wrong here? Is there any good documentation on these matters? Thanks! Olaf
👀 1
i
I'm sorry for the late response. You may try to add
isStandalone(false)
to your
ScriptCompilationConfiguration
. Although this is an old change - scripts with definitions without it are ignored in source roots by default. So it is quite suspicious that you're seeing it only now, but maybe something else was at play. For example there is a workaround with
-Xallow-any-scripts-in-source-roots
compiler flag.
If it doesn't help, please create an YT issue - maybe it's an IDE bug after all.
o
Hi Ilya! I tried your
isStandalone(false)
but still, nothing changes. The scripts are not getting their default imports at all, they are basically completely broken in IntelliJ. I would like to open a YT issue, but can it really be I am the only one who uses this? Is there any kind of documentation I can read again, like a demo project that showcases this rather odd setup with the "magic"
ScriptCompilationConfiguration
class and the magic resource file
META-INF/kotlin/script/templates/...
? I would like to test that in order to even write a proper YT issue as I cannot post all of my script language code. Thanks!
i
Hi Olaf! The combination should be supported in principle, because it is used for the Gradle precompiled scripts, that work fine with K2. But I'm not sure that we tested it thoroughly, so it maybe indeed be a bug here that surfaces in your case. In general, compiling scripts with other sources (via e.g.
isStandalone(false)
) is considered quite an advanced case, where you need to understand quite well how your scripts will interact with the other sources in the project. Therefore, we hide it under the opt-ins, and thus, we hope, there are not many users who use this. Anyway, I recommend you to file an issue as is, using just the description you gave above, and we'll test the functionality on our tests and come back to you on it later. cc: @Vladislav Koshkin
👀 1
o
Hi @ilya.chernikov, turns out that everything works as expected once I switch off K2 Mode in IntelliJ... 😞 With K2 Mode enabled, my scripts are not rendering/working as before...
v
hi, I'll also take a look into that this week loading
👍 1