-
Notifications
You must be signed in to change notification settings - Fork 255
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
base: main
Are you sure you want to change the base?
Conversation
- 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. ✅ |
|
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 |
That would be perfect! Thanks! |
|
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D90510122. |
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