Add setting to allow folding function signature separately from body #3913
Replies: 14 comments 2 replies
-
Python disabledExpandedCollapse signatureCollapse bodyCollapse allPython enabledExpandedCollapse all |
Beta Was this translation helpful? Give feedback.
-
We previously discussed this in #2269. Take a look at the three options I described in this comment. Option 1 is your preferred behavior. Let me know what you think. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick reply @debonte ! I agree with you, option 3 is a good intermediate approach. The important thing imho is to be able to keep the signature visible. Only concern with option 3 really is that it would mess up the levels so that shortcuts will not be consistent (e.g. folding level 2 would mean folding the body in some functions, and folding something internal in other cases depending on whether the signature is multiline or not) That is why I would personally advocate for option 1. Plus the overall underlying data structure seems more natural to me, so easier to understand as a user. Thanks for putting all this together 😉 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Some other thoughts:
|
Beta Was this translation helpful? Give feedback.
-
Thanks so much for the detailed response! This is what I mean. Take the following code snippet as an example, folding points are labeled alphabetically: def single_line(): # A
if 0 == 1: # B
pass
def multi_line( # C
*args,
): # D
pass Folding level 1 means:
Folding level 2 means:
Notice how folding level 1 is roughly equivalent and equivalent; with the added choice of displaying the signature under option 1 afterwards. However, folding level 2 under option 3 messes the structure of the document, since one function will get its body folded and the other only an internal You can toy around with this idea and notice that the real issue with option 3 is that it assigns different precedence levels to things which are structurally at the same "height": throwing the body under the signature instead of keeping them aligned in the hierarchy.
This would be a nice way to end the controversy, let users choose what they want.
In which case this would help remind them what their selected choice is 🙂 but it is not a huge concern of mine. I think people can get a grasp of the behavior by simply clicking a few times |
Beta Was this translation helpful? Give feedback.
-
Thanks. I'm embarrassed to say that I wasn't familiar with the I'll need to think about this some more and play with the different behaviors. Thanks for educating me. :) |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I agree that option 3's behavior with the If there's sufficient interest, we can add a setting to choose between options 1 and 2 for folding functions (and classes) with multi-line signatures/headers. However, given that no one else has upvoted or commented on this issue, it's not clear that it's broadly needed. @pedrorrivero, can you try this setting to see if it is acceptable to you as a workaround in the meantime? "[python]": {
"editor.foldingStrategy": "indentation",
}, |
Beta Was this translation helpful? Give feedback.
-
@pedrorrivero, ping? See my comment above. |
Beta Was this translation helpful? Give feedback.
-
Apologies, I've had very busy weeks. Let me take a look at this over the weekend! Thanks for pinging @debonte 🙂 |
Beta Was this translation helpful? Give feedback.
-
This looks very nice indeed, for what I have been able to see it does exactly what we discussed for option 1, thanks a lot for taking a look and providing a solution @debonte. Looking forward to that extra option in the future if there is interest 😄 Let me know if I can help in any other way |
Beta Was this translation helpful? Give feedback.
-
Quick update @debonte, the workaround you proposed fails for docstrings (i.e. they cannot be collapsed). |
Beta Was this translation helpful? Give feedback.
-
I think fine control on folding is not exactly what we're looking for when raising this issue. At least, in my case it was the need to see function signatures while functions are collapsed. So as an extension to the current behavior, how about adding a configuration for:
This configuration should be toggle-able in an open file without changing the global, workspace or folder settings json. cc @debonte |
Beta Was this translation helpful? Give feedback.
-
Type: Bug
Behaviour
Expected vs. Actual
When the Python plugin is disabled, function/class bodies in
.py
files can be folded from the end of a multiline signature (i.e. at:
); while the multiline signature can also be folded separetly at the same level. Enabling Python, breaks this nice behavior, only allwoing to fold the entire function from the first line of the signature (i.e. atdef
/class
).This is, enabling Python joins signtaures and the bodies in a single foldable, instead of keeping them separate.
Steps to reproduce:
.py
file with a multiline function/class signaturedef
/class
height, and another to fold the body at:
height..py
file.py
filedef
/class
height which folds both the signature and bodyDiagnostic data
python.languageServer
setting: DefaultOutput for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)User Settings
Extension version: 2022.14.0
VS Code version: Code 1.71.2 (Universal) (74b1f979648cc44d385a2286793c226e611f59e7, 2022-09-14T21:05:37.721Z)
OS version: Darwin x64 21.6.0
Modes:
Sandboxed: No
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Beta Was this translation helpful? Give feedback.
All reactions