Issues about IDEA support of Kotlin script (.kts)


#1

By creating a .kts file and copying the code snippet at https://kotlinlang.org/docs/tutorials/command-line.html#using-the-command-line-to-run-scripts into it, the editor marks “args” as an error but the code can be run correctly.

Did I miss some settings or it’s a small bug of IDEA?

Also, the debug icon is de-activated. Will it be enabled in the future?

Thanks.

This is the version I used:
IntelliJ IDEA 2017.3.3 (Ultimate Edition)
Build #IU-173.4301.25, built on January 16, 2018
JRE: 1.8.0_152-release-1024-b11 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.13.2


#2

I’m able to run (though not debug) *.kts files through IntelliJ.

I installed the Kotlin compiler via homebrew. I also had to specify a JDK in the project configuration as one was not configured by default. Here’s the version info:

$ kotlinc -version
info: kotlinc-jvm 1.2.21 (JRE 1.8.0_152-b16)
IntelliJ IDEA 2017.3.4 (Ultimate Edition)
Build #IU-173.4548.28, built on January 29, 2018
JRE: 1.8.0_152-release-1024-b11 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.13.3

Also, the sample code snippet takes a directory as an argument, so you’ll want to provide that as program argument in the run configuration.


#3

I experience the same as ckchen with these versions

➜  tmp kotlinc -version
info: kotlinc-jvm 1.2.21 (JRE 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
IntelliJ IDEA 2017.3.4 (Ultimate Edition)
Build #IU-173.4548.28, built on January 29, 2018

JRE: 1.8.0_152-release-1024-b11 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-32-generic

The script does run fine, the problem is that IDEA does not validate the code correctly and falsely reports 4 errors in 3 lines of code:

Is this a configuration problem? Do we miss some settings?

Also, in scripting I want to pass exit codes to the calling shell to indicate success or failure of the script run. I tried to do that with exitProcess (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.system/exit-process.html), but that reults in error: unresolved reference: exitProcess. What is the recommended way to return an exit code from a kotlin script?

Thanks,
Thilo


#4

Does System.exit(n) not work?


#5

Thanks, @reitzig.1! Your reply solved both of my problems:

  1. As of this morning I cannot reproduce any more the IDE problem. The errors in IDEA have disappeared magically (on my Linux installation as well as on Windows. :mage:)

  2. yes, System.exit(n) works, as well as exitProcess(n), where now IDEA kindly offers to add

    import kotlin.system.exitProcess

#6

Sometimes just restarting helps :wink: