-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make cells (# %%) collapsible python files #1527
Comments
I believe the only way to do this would be with the outline support VS Code has already: As far as I can tell, the start line remains visible, so you'd probably end up with something like: #%% #%% #%% With no clear indication what cell was what. Maybe combined with a decorator provider, it could also stick in the first line of code after the cell header. |
I am also waiting for this feature. It may be simple as described by @DonJayamanne in microsoft/vscode-python#10503
The feature may be very similar to the |
Is there anything new ? This should be set to important because I believe most of data science and ml guys write long jupyter notebook. And we are used to collapse those cells in Colab. |
Sorry but this isn't on our radar at the moment. It's waiting for more people to up vote it. |
I upvoted. Both the other notebook platforms I use, Google Colabs & Mathematica, have this feature natively. The reasoning is sound: A lot of times in data sci applications certain cells are no longer required to be updated frequently and it reduces clutter. Not being able to collapse cells in VS Code's implementation of Jupyter notebooks has been being bugging me for months, and I was just thinking this weekend about porting some project files over to Colabs because it's a cleaner coding experience. It can't really be considered an edge feature request anymore. It's a minimal viable product requirement now in my opinion. |
I upvoted. It is the reason preventing me to use VSCode as a notebook editor. The Microsoft team working on https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-github-issue-notebooks already implemented collaspsible section as well as drag and drop of cells in notebooks. (cf screenshot or VSCode insider required to test for now) Could you reuse their work? |
Yes this is the plan. We'll be using that same API to rewrite how we support jupyter notebooks. |
Is there any update on this? I agree with previous comments that this is a huge headache when using VScode for Jupyter notebooks |
This comment has been minimized.
This comment has been minimized.
It should be noted that this issue microsoft/vscode-python#5227 is actually about adding another collapse region into a python file with cells. Cells are usually delineated with This issue is not actively being pursued by our team but we welcome PRs if somebody else finds the time to get to this. |
@rchiodo Not sure if u are joking or serious but I think the original request was about collapsing the cells only. 😊 Also, isn't this same as microsoft/vscode-python#10503 and #957?? For those who are very desperate can type "if True:" on the top of the cells which you want to hide. Then u can fold them. It is surely not very efficient but it will serve the purpose for the time being. 😉 |
@PrateekArya not sure what you are wondering what I'm joking about? Submitting PRs? External contributors have done a bunch of work in the past. Collapsable regions is not high on our backlog at the moment but if somebody else really wants it, we would certainly love any submission. I believe the solution to this request would be to add a FoldingRangeProvider: In our code where we create code lenses, it probably wouldn't be too hard to add a folding range provider somewhere there. |
For anyone interested here's a sample implementation (created for folding of docstrings). |
I think it is better to use the Sorry, I really thought this issue was easy to provide (replacing |
Would |
You can add comments directly after |
It has been more than 2 years, since the original post... |
For anyone still waiting for this (like me), I found a way that worked for me. It is the simple setting bellow (in case it help someone): Expand the "Regular expression used to identify code cells" (in the settings) to also recognize the expression
Now the cells also starts with |
Yes, it works! But I am using a modified version as follows so that I can also write comments on the top of my cells: Here if u just want to copy it: Now, I write the cell headers as: and the end of cell and starting of next cell as: My folded cells looks like this: |
Nice! But just to make it clear: you regular expression requires that the cell starts with Basically, you have not added a new pattern but modified the regular That is ok. But if you find working with some file with the previous pattern BTW, any of that patterns allow you to write comments on the top of cells. |
Yes. I agree! :) |
@Diogo-Rossi Thanks your fix works...I am currently using VSCode Insider V.1.60. Accidently I was able to make the usual # %% collapsible. Write # %% + press enter + tab + # region. |
Really creative and interesting! Given the above you could take it to the next step and create a snippet.
"Collapsible Python Cell": {
"scope": "python",
"prefix": "cc",
"body": [
"# %%",
" # region",
"$0"
" # endregion"
],
"description": "Insert a collapsible pythoh cell for execution in the Interactive Window"
}
It's not the perfect solution, and you'll probably want to turn off the setting |
I found a better solution. Maybe you are interesting too.
Now everything works.
|
@Diogo-Rossi thanks for the solution, it works seamlessly.
We could probably register a similar folding range provider in Jupyter oob. |
Hello,
|
@otaolafranc |
Environment data
Expected behaviour
In a document with multiple cells, collapsing some of them improves usability.
Actual behaviour
It is not possible to collapse cells.
Some Details
I think defining
#%%
as (collapsible region start) shouldn't be very hard (I can try to submit a PR in 1-2 weekends if you agree with the idea).Some implementation details should be evaluated though:
#%% Comment ...
would be the default I think)Run below|above
Run Cell | Run Above | Run Below
The text was updated successfully, but these errors were encountered: