Is there a docblock tag to create a subsection in the structure toolbar?

I like to use the structure toolbar in PhpStorm to jump between functions and keep a general overview over the structure of a class. However, the toolbar only shows functions for navigational points. Some classes have methods that can be understood as belonging to a certain logic. Colleagues and I myself have therefore started using docblocks to structure the files further.

I would like to use a tag in the docblocks that adds additional subsections in the structure toolbar, just like an anchor in an html file. Is there something like this?

I looked up the available tags on https://docs.phpdoc.org/latest/guide/references/phpdoc/tags/index.html but did not find any tags that offered the requested functionality. I included the IDE in this question since I am open to using an extension if that would offer a solution.

Upvotes: 0

Views: 84

Answers (1)

LazyOne
LazyOne

Reputation: 165088

Docblock tag? No.

But yes, you can create sections in the Structure panel. Just use custom code folding region and give it a description.

NOTE that this means that you have to have 2 comments: opening and closing one that denote the start and end of the block. You can also even nest them.

Here is how it may look (in a CSS file for example):
enter image description here

Using <editor-fold> XML like syntax.

  • pros: can specify default folding state
  • cons: a bit too descriptive
//<editor-fold defaultstate="collapsed" desc="=== My First Block">
callingSomeFunc($param1, $string);
//</editor-fold>

Using region syntax:

  • pros: short and sweet
  • cons: cannot specify default folding state
//region My Second Block
function callingSomeFunc($param1, $param2)
{
 // ... code
}

callingSomeFunc($param1, $string);
//endregion

NOTE: you cannot mix multiple styles in the same file -- you have to stick to the one of them.

See the following related answers (with screenshots of how it looks etc):

Upvotes: 0

Related Questions