Skip to content
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

TOC for .py files with percent markup #17218

Open
brettcannon opened this issue Sep 1, 2021 Discussed in #15990 · 14 comments
Open

TOC for .py files with percent markup #17218

brettcannon opened this issue Sep 1, 2021 Discussed in #15990 · 14 comments
Labels
area-editor-* User-facing catch-all community ask Feature request that the community expressed interest in feature-request Request for new features or functionality needs proposal Need to make some design decisions

Comments

@brettcannon
Copy link
Member

Discussed in #15990

Originally posted by syagev April 19, 2021
I suggest to have a TOC available for .py files with percent markup. I guess for that we'll need to have the user select which kind of "Outline" view is of interest - the one for regular code files (which will not pickup e.g. markdown cells), or the one adjusted for notebooks.

My use case - in our team we manage a big .py file that acts as a sort of "catalog" of useful and relatively independent cells. This has to go under source control for version management and collaboration. The typical workflow is then to open an Interactive Window and execute a few of the cells of interest. So for finding these cells in the large file the described TOC is useful.

Originally posted by @syagev in microsoft/vscode-jupyter#1348 (comment)

Also opened as issue under vscode-jupyter microsoft/vscode-jupyter#5552 since I'm not sure where the right place is.

@brettcannon brettcannon added feature-request Request for new features or functionality needs decision area-editor-* User-facing catch-all labels Sep 1, 2021
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 1, 2021
@brettcannon brettcannon removed the triage-needed Needs assignment to the proper sub-team label Sep 1, 2021
@brettcannon
Copy link
Member Author

Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 5 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.

@brettcannon brettcannon added needs community feedback Awaiting community feedback and removed needs FR policy labels Sep 1, 2021
@GitHunter0
Copy link

I believe most users are still not aware of this new issue, it is such an indispensable feature that it would be shocking if it cannot get 5 upvotes. To me it is a no-brainer that every single IDE should have it.

Thanks for opening this issue.

@GitHunter0
Copy link

GitHunter0 commented Sep 30, 2021

Just repeating the 2 suggestions I made in another issue.

(1) The hierarchical section system of Spyder IDE seems a good one to implement:

#%% Section
#%%% Subsection
#%%%% Subsubsection
And so on

(2) Since VScode is providing native conversion from .py files to notebooks (.ipynb), it would be nice to have a syntax that allows the user to go back and forth between .py and .ipynb maintaining code sections, markdown sections and TOC intact.

EDIT (2023) another suggestion:

(3) Assign keyboard shortcuts to go to the previous / next code cell.

@brettcannon
Copy link
Member Author

Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future.

We do encourage people to continue 👍 this issue as it helps us prioritize our work based on what the community seems to want the most.

@brettcannon brettcannon added community ask Feature request that the community expressed interest in needs proposal Need to make some design decisions and removed needs community feedback Awaiting community feedback labels Nov 1, 2021
@ChuandongXie
Copy link

So has the hierarchical section system mentioned by @brettcannon @GitHunter0 already been introduced into VS Code? I try to find this feature but it seems haven't yet.

@brettcannon
Copy link
Member Author

@ChuandongXie nothing specific from our extension has been introduced (although there may be some other extension that provides the feature). If/when we work on this we will post an update to this issue accordingly.

@LiuWenJia-ops
Copy link

A feature that is very important to me! I often write lines of code as drafts, before I officially code.

@wilsonchen719
Copy link

Please implement the feature. Too important!

@chenweifelix
Copy link

I'd like to resurface this request. As a user of both R and Python, I found it very inconvenient that in .py file, I can't mark sections and navigate within my code as I do in .R within vscode. Please help implement this feature, as I believe many other R and python users would benefit from it. Plus, it would also help those considering switching from other python IDE to vscode, as mentioned in the previous comment.

@kebuAAA
Copy link

kebuAAA commented Apr 23, 2024

With the March 2024 (version 1.88) update releasing, the Minimap section headers may be an alternative. I have to admit that this feature is a bit of a departure from adding toc considering that it doesn't offer multiple levels of titles.

@zouter
Copy link

zouter commented Jun 5, 2024

For those still looking for this: I found the extension regexpOutline extension really works well to implement this.
Here's the "headerRulesEachExt" setting if you are using markdown headers:
[{"ext": ".py","rules": [{"level": 1,"format": "^# #(.+)$","nameIdx": 1,"detail": "H1"},{"level": 2,"format": "^# ##(.+)$","nameIdx": 1,"detail": "H2"},{"level": 3,"format": "^# ###(.+)$","nameIdx": 1,"detail": "H3"}]}]

As an added bonus, symbols are also registered you use Ctrl+P -> @header to find the headers using just your keyboard.

@peekxc
Copy link

peekxc commented Jun 10, 2024

[{"ext": ".py","rules": [{"level": 1,"format": "^# #(.+)$","nameIdx": 1,"detail": "H1"},{"level": 2,"format": "^# ##(.+)$","nameIdx": 1,"detail": "H2"},{"level": 3,"format": "^# ###(.+)$","nameIdx": 1,"detail": "H3"}]}]

@zouter I'm unable to get this to work, though I think it's a problem with the extension. What does this look like exactly in your settings.json?

@zouter
Copy link

zouter commented Jun 12, 2024

[{"ext": ".py","rules": [{"level": 1,"format": "^# #(.+)$","nameIdx": 1,"detail": "H1"},{"level": 2,"format": "^# ##(.+)$","nameIdx": 1,"detail": "H2"},{"level": 3,"format": "^# ###(.+)$","nameIdx": 1,"detail": "H3"}]}]

@zouter I'm unable to get this to work, though I think it's a problem with the extension. What does this look like exactly in your settings.json?

@peekxc Might be that you need to escape. This is how the settings.json line looks like:
"regexpOutline.headerRulesEachExt": "[{\"ext\": \".py\",\"rules\": [{\"level\": 1,\"format\": \"^# # (.+)$\",\"nameIdx\": 1,\"detail\": \"H1\"},{\"level\": 2,\"format\": \"^# ## (.+)$\",\"nameIdx\": 1,\"detail\": \"H2\"},{\"level\": 3,\"format\": \"^# ### (.+)$\",\"nameIdx\": 1,\"detail\": \"H3\"},{\"level\": 4,\"format\": \"^# #### (.+)$\",\"nameIdx\": 1,\"detail\": \"H4\"}]}]",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-editor-* User-facing catch-all community ask Feature request that the community expressed interest in feature-request Request for new features or functionality needs proposal Need to make some design decisions
Projects
None yet
Development

No branches or pull requests