pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Add a "fold all docstrings" command

Open rchiodo opened this issue 2 years ago • 5 comments

Discussed in https://github.com/microsoft/pylance-release/discussions/3933

Originally posted by jonasreiher December 8, 2022 Docstrings covering all input parameters, types and precise function/class descriptions can become quite long and get in the way of the actual code. Usually, you only need to look into them when writing them or when looking up a specific function/class and it would be preferable to have them folded most of the time. You can do this by clicking the arrow next to the line numbers for each of them. This becomes tedious for files with a lot of docstrings, though.

There exists the "fold all block comments" command in VS Code but docstrings are not considered as block comments since they have the same format as multi-line strings and you wouldn't want to fold them away (see microsoft/vscode-python#20330). Proposal: a "fold all docstrings" command that, well, folds all docstrings, so multi-line strings that are the first item in a function/class definition.

Alternative proposal: classify all multi-line strings as block comments that are are not inside of a function call or variable assignment. This would be consistent with the "toggle block comment" command that wraps the selection in triple quotes. Creating a block comment like this but then not being able to fold it with "fold all block comments" seems contradictory.

rchiodo avatar Aug 01 '23 23:08 rchiodo

Thought this might be a good thing to do in the near future.

rchiodo avatar Aug 01 '23 23:08 rchiodo

Good to see that this nuisance is getting tackled. Here is a similar request from me in PTVS - it would be good if the solution were applicable in VS, too.

https://github.com/microsoft/PTVS/discussions/7412

excubo-jg avatar Aug 02 '23 13:08 excubo-jg

Unfortunately, I believe PTVS would have to be done separately. The same commands don't apply to Visual Studio.

rchiodo avatar Aug 02 '23 16:08 rchiodo

Historically related: microsoft/vscode-python#20330

Related on Stack Overflow: The "Fold All Block Comments" command doesn't work on Python docstrings in files with certain arrangements of import, where it was also discovered that interestingly, the Fold All Block Comments command does actually affect docstrings, but only under certain conditions which are not precisely known by me or the asker of that question. Not sure if that's intended or not.

starball5 avatar Aug 07 '23 21:08 starball5

I made a vscode extension to tackle this exact problem, as it was bugging me so much: https://marketplace.visualstudio.com/items?itemName=DanielSanchez.docstring-fold-and-unfold

danidss avatar Oct 07 '24 01:10 danidss

This issue has been fixed in prerelease version 2024.10.102, which we've just released. You can find the changelog here: CHANGELOG.md

heejaechang avatar Oct 24 '24 21:10 heejaechang

I found this listed on the release notes but had to came here to find out it is "pre-release"

diogo-rossi avatar Nov 04 '24 12:11 diogo-rossi

@Diogo-Rossi, sorry for the confusion. Our stable release was delayed due to a regression that we found late in the testing process. The stable release will probably ship today.

debonte avatar Nov 04 '24 16:11 debonte

This feature is now available in stable release 2024.11.1, which we've just released.

debonte avatar Nov 04 '24 20:11 debonte