How to collapse/expand all comment blocks in a file in PhpStorm?
Asked Answered
P

1

9

In PhpStorm, what is a quick way to collapse or expand all the comment (doc) blocks in a file?

In the docs here it says:

Folding and expanding code blocks works for entire classes, inner and
anonymous classes, method bodies, import lists, comments, HTML and XML tags,
closures and language injections.

And then further down says:

If you hold the Alt modifier and click a toggle button in the gutter, the code block
will be collapsed or expanded recursively, i.e. all sub-blocks within the parent 
block will also be collapsed or expanded.

But I'm not seeing how this Alt modifer works? I hold Alt then click the toggle button and only that block alone collapses. I tried this in the top class doc block, and also in the property/method doc blocks. Am I missing something?

Prismatic answered 5/2, 2015 at 21:52 Comment(9)
Are you trying to collapse every code block in the file, or just the ones nested within the one you are Alt+clicking?Boarish
On that doc page it says: "Expand all code blocks in the selected area, or in the current file if no area is selected ", so ` Ctrl+Shift+NumPad+ ` and ` Ctrl+Shift+NumPad- `Brindled
I'm trying to collapse all of them in the file. But what do you mean by "nested"? How would there be comments nested inside of comments? (Unless the comments are on child method/properies of a class, but I tried doing this on the parent class and nothing changed with the doc blocks of the child method/properties)Prismatic
You would have to use Ctrl+Shift+<Minus> to collapse everything. Even their docs indicate that "Collapse doc comments" has a shortcut of "N/A" jetbrains.com/phpstorm/help/…Boarish
The "Alt" modifier is used if you want to recursively collapse (for non-commented code: nested if/for statements, etc.). The folding menu on the documentation page is your best point of reference.Boarish
@MikeK exactly, their docs say "N/A" for a keyboard shortcut. So I'm trying it the only other way the docs say, as pointed out in my question.Prismatic
But their docs doesn't say that it will work that way. It will only collapse that block and everything inside of that same block.Boarish
What does it mean by recursively? I mean, when I click the toggle, everything folds, no matter what it is. Pressing Alt does nothing differently.Prismatic
Hmm...it's looking like it's not possible @MikeK. Thanks for your help though! Maybe I'd have to see if some sort of plugin can be written to do this.Prismatic
T
23

In PhpStorm, what is a quick way to collapse or expand all the comment (doc) blocks in a file?

Code | Folding | Collapse/Expand doc comments

enter image description here

By default it has no shortcut, but it can easily be added in Settings (Preferences on Mac) | Appearance & Behaviour | Keymap -- any shortcut you want.


But I'm not seeing how this Alt modifer works? I hold Alt then click the toggle button and only that block alone collapses. I tried this in the top class doc block, and also in the property/method doc blocks. Am I missing something?

Yes.

What does it mean by recursively?

It means nested constructions that could also be collapsed.

I mean, when I click the toggle, everything folds, no matter what it is. Pressing Alt does nothing differently.

Really?

Sample code:

<?php
class SomeClass
{
    public static function makeImageName($id, $sequence = 0, $sizeId = '')
    {
        $group = floor($id / 100);

        if ((int)$sequence > 0) {
            $suffix = '-' . $sequence . $sizeId;
        }
        else {
            $suffix = $sizeId;
        }

        return "/catalog/product/{$group}/{$id}/{$id}{$suffix}.jpg";
    }
}

After Alt + Click on a function node:

enter image description here

Now expand that function back via "normal" Click:

enter image description here

As you can clearly see the if and else nested blocks are still collapsed.

Treed answered 6/2, 2015 at 10:57 Comment(1)
Don't know how I missed this answer, sorry for just seeing this now!!Prismatic

© 2022 - 2024 — McMap. All rights reserved.