Quick question: Does anyone know of a tool to expa...
# getting-started
j
Quick question: Does anyone know of a tool to expand star imports in Kotlin? (IntelliJ optimize imports does not do it.)
j
> IntelliJ optimize imports does not do it The formatter should, if you configure it not to use star imports at all
1
j
It doesn't.
If it's supposed to, where do I file a bug?
j
Ah sorry, not the formatter, but the optimize imports action should. I just tested it in IDEA and it works fine. What are your code style settings for Kotlin?
j
image.png
If I comment out the star import, it generates non-star imports. But that doesn't always work because of ambiguity.
Is it maybe a K2 thing?
j
Strange. Which version of IJ are you using? In my case with IntelliJ IDEA 2024.3 EAP it seems to automatically change
*
imports to their explicit variant.
j
2024.2.1 (CE)
j
Is it maybe a K2 thing?
I have K2 mode enabled. Not sure if it will change something for you
j
Same. Very weird.
j
Then maybe open an issue on YouTrack, you'll probably get answers (or questions!) from the right people (although I have the JetBrains tag, I'm not part of the Kotlin team, I'm just a Kotlin user 😉 )
j
ok, ty 😄
o
If you invoke
Ctrl + Alt + Shift + L
, it presents a dialog - see if you have "optimize imports" checked there. If not, try that. You probably don't have that checked, so the autoformatter doesn't touch existing imports.
j
It is checked.
o
One other suggestion that comes to mind is using
.editorconfig
file with the following options:
Copy code
[*.kt]
ij_kotlin_name_count_to_use_star_import = 99
ij_kotlin_name_count_to_use_star_import_for_members = 99
j
Did that, doesn't work.
It is definitely a bug of some kind.
👌 1