Feature Request: Improve Structure View with Custom Section Support

Answered

Dear JetBrains PyCharm Team,

I would like to suggest an improvement to the Structure View in PyCharm.

The current Structure View is very useful because it provides a clear overview of classes, functions, and other code elements. However, it only displays automatically detected code structures. For larger files, it would be helpful to allow users to add custom section titles to organize the view.

For example:

# SECTION: Data Loading

def load_data():
    pass


# SECTION: Data Processing

def clean_data():
    pass


# SECTION: Model Calculation

def calculate_result():
    pass

The Structure View could display:

Data Loading
    load_data()

Data Processing
    clean_data()

Model Calculation
    calculate_result()

This would make the Structure View more flexible without changing the code execution or language syntax. User-defined sections could simply act as organizational nodes in the tree.

Classes and functions are already displayed as structural elements. Adding section titles would provide another useful layer of organization, especially for files that are large but still logically belong together and do not need to be split into multiple modules.

A possible implementation could be based on a customizable comment pattern, similar to the existing TODO feature.

Thank you for considering this improvement.

Best regards

0
2 comments

This is a great idea! I used to use #pragma marks all over the place in Xcode. In python I find myself writing these big visual comment blocks instead, but they just aren't the same.

0

We actually have an older feature request for this - PY-35194

Please vote and follow it there so you get updates, and votes help us prioritize it.

In the meantime, # region Some name / # endregion comments already give you collapsible folding regions in Python. They just do not show up as nodes in the Structure view yet

0

Please sign in to leave a comment.