phpphpstormcommentsdocblocks

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


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?


Solution

  • 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.