Auto-collapse for Imports does not work when auto-formatting code

Looks like the latest couple of updates to WebStorm 2024 may have broken (or changed) how the imports auto-collapse works. It used top be that imports stayed collapsed unless you manually expanded it. I've always liked that, as it keeps imports out of sight, as I am a heavy user of auto-import features, and I very, very rarely manage imports manually. So I like them tucked away and hidden at the top of my files. 

Since upgrading to the two latest versions of WebStorm (from the last version of 2023), this no longer works the same. Every time I auto-format a file, which I use both WebStorm's built-in formatting and prettier formatting to get the formatting I most prefer, the imports are expanded, and they stay expanded. Once expanded this way, it seems the auto-collapse for imports no longer works, and I have to manually collapse them. Which only works, until then next auto-format, then they expand again.

This effectively nullifies import auto-collapse, making them always visible (I auto-format very often using hotkeys.) 

0
3 comments

Unfortunately I failed to reproduce the issue: if the imports section is folded, its state is preserved on reformatting.
For the files opened for the first time, folding state on opening/re-formatting corresponds to code folding preferences. Do you have Prettier enabled for your project?


Please note that code folding preferences only work on initial file loading, folding state of opened file is saved in .idea/workspace.xml and restored in file reopening. See Fold by default option description (https://www.jetbrains.com/help/webstorm/code-folding-settings.html): 

Select the code fragments which should be folded by default,    that is, when a file is first opened in the editor.

0

Hmm. Well, something seems to have changed from before the latest 2024 versions. I'm a prolific auto-formatter. I format with webstorm, then format with prettier. If I format only with prettier, there is no issue with the imports section expanding. It only seems to occur when I format with webstorm's built-in formatting (which is far more capable than prettier). Every time I format now, my collapsed imports section always expands. 

0

Do you have Prettier enabled in Settings | Languages & Frameworks | JavaScript | Prettier? Also, would you be able to confirm whether the Optimize Imports is turned on in Code > Reformat file?

0

Please sign in to leave a comment.