IntelliJ: fold open struct/enum, fold close impl

  1. IntelliJ has code folding Code Folding | IntelliJ IDEA , basically this means that
blah blah blah {
  lots
  of
  code
  here
}

can appear as blah blah blah { ... } (on a single line

  1. Now, in *.rs files, I have this problem where it is hard to scroll through all the "impl { ... }" code blocks.

Question: is there a way in IntelliJ/Rust, to setup code folding so that the default state is:

  • for struct/enum, default to open
  • for impl, default to close

?

Basically, when I open a *.rs file, I would like to see:

  • internals of structs/enums
  • what traits are implemented (but not the actual implementations)

You could just Collapse All in the file. I think that the default keybind is Ctrl+Shift+Numpad -, but my keymap might be a bit off, so I don't know.

Check your keybind by doing Shift+Shift+Shift and searching for Collapse All.


As a side note, this really does seem like a job for rustdocs.

CollapseAll / CollapseAllRegions seems to collapse the structs too. If only we had a way to somehow mark them as "do not collapse"

But then we lose things like being able to edit. :slight_smile:

Just to clarify, have you tried enabling "fold method bodies by default"? This is not exactly what are you asking for, but it feels close enough (And one of the things I personally find quite indispensable and miss in VS Code a lot).

This is Editor > General > Code Folding

fold by default:
  General ---------------------
    [X] method bodies

?
(sorry, bad at screenshot on Linux)

II tried it just now, it is not doing anything for me. I may have misconfigured something else.

I am currently just using "zM" (collapse everything in IntelliJ/VIM mode). I have adjusted to all the structs/enums being folded/collapsed.

Huh, that's weird... I am almost ready to swear it worked before :slight_smile: reported: "Fold method bodies by default" doesn't work with Rust? · Issue #7058 · intellij-rust/intellij-rust · GitHub

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.