Hi all, I'm having trouble getting code completion...
# scripting
s
Hi all, I'm having trouble getting code completion in IntelliJ to work with my custom Kotlin scripts. After reading through https://github.com/Kotlin/KEEP/blob/master/proposals/scripting-support.md#how-to-implement-scripting-support I've added a
.classpath
file to my project's
META-INF
directory, but it seems I also need to add my project's JAR now to the compiler's classpath. How do I actually do that from the IDE? My code changes can be seen at https://github.com/oss-review-toolkit/ort/pull/4887/files#diff-b5d75d77219b5108e66671916d8001890961d0063bbff4e606b13d286374908e.
b
Should be working out of the box if you name your file as xxx.main.kts
s
Well, that's the point: I have custom scripts (with a custom DSL, custom default imports etc.) so I can't / don't want to use
.main.kts
directly, but build my own.
In particular, I'm interesting in whether it's possible to add IDEA completion support for custom scripts without writing an IDEA plugin. The instructions in
scripting-support.md
are a bit unclear about that. It sounds as if it could also be enough to just create a
.classname
file at
META-INF/kotlin/script/templates/
and add the corresponding JAR to the compiler's classpath.
Looks like I was able to get it working. The main problem seemingly was that I had the script configuration (annotated with
@KotlinScript
) and the script to run in the same IntelliJ model / project JAR. Splitting out the script configuration into a separate project, and making the project containing the scripts (as resources) depend on that project solved the highlighting / auto-completion issue, which now works in IntelliJ IDEA.