Auto-completion in kotlin main-kts scripts which uses @file:import

It seems IntelliJ auto-completion for kotlin scripts does not work across @file:import("other-file.kts") Is that correct at the time of writing for you others as well?

I’m using kotlin 1.6.20, windows, IntelliJ 2021.2.4.

I can get auto-complete to work on main-kts files, but it won’t include anything from other imported file with @file:import. For example in this file I cannot auto-complete type of a if I say val a = sharedVar, because sharedVar is from another file:

In fact its only on a rare occasion that IntelliJ will auto-complete anything in files with @file:import

I also created a smaller sample library here with an autocomplete-fails.main.kts file:

4 Likes

A year later same problem on IntelliJ IDEA 2023.1.2 (Ultimate Edition). Did you find a workaround? This makes Kotlin Script way less appealing :face_holding_back_tears:

No I havn’t found a solution. I don’t use kotlin scripting at the moment, I’m waiting for it to mature. Without auto-completion I would rather just have full-blown multi-dir gradle project, though the result being that I’m still mostly using powershell for small script. Sadly…

Ugh, sadly, this is still an issue. I have tons of scripts written in Kotlin, run by KScript project. Wanted to migrate them all to .main.kts to get IDE support. But sadly, there still appears to be poor support. One of the issue is the auto-completion not working for @file:import as you mentioned :frowning: