-
Notifications
You must be signed in to change notification settings - Fork 239
Support section-folding comments in Python (similar to R’s # ---- convention)
#2024
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
Open
kv9898
wants to merge
9
commits into
facebook:main
Choose a base branch
from
kv9898:feature/comment-section
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+760
−2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Add comment_section module to parse Python comment sections (# Section ----) - Integrate comment sections into folding ranges with hierarchical support - Integrate comment sections into document symbols with nesting - Add tests for folding ranges with comment sections - Add tests for document symbols with comment sections Co-authored-by: kv9898 <[email protected]>
- Fix fragile parent matching in document symbols using path-based approach - Add safe integer conversion for file lengths to avoid overflow - Document behavior for extremely long lines in comment sections Co-authored-by: kv9898 <[email protected]>
- AST symbols (variables, functions, classes) are now children of their preceding comment section - Symbols between sections are properly nested in the section hierarchy - Updated test expectations to reflect new nested structure - Added comprehensive test for the exact user scenario Co-authored-by: kv9898 <[email protected]>
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Contributor
|
Thanks for the PR! Assigning to @yangdanny97 because our team chatted about this - we'd like to support the feature which seems useful, but we also want to make sure it doesn't interfere with traditional semantic folding, so we may add decide to a feature flag for this behavior so that it is opt-in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #2019.
Implements structured comment headers for code organization, inspired by R's convention. Sections like
# Title ----(4+ trailing delimiters:-,#,=) create hierarchical structure based on#count.Example:
Outline and folding:

Provides:
Implementation
comment_section.rs: Regex-based parser (^(#+)\s+(.+?)\s+([-#=]{4,})\s*$) extracts sections with level detectionfolding.rs: Integrates sections asFoldingRangeKind::Regionwith hierarchical folding supportdocument_symbols.rs: Sequential processing of statements and sections. AST symbols are added as children of the current section context. Uses path-based navigation for robust parent-child relationships in the symbol tree.Test Plan