Add syntax-aware enclosing definitions and folded output - #3998
Open
Matei02355 wants to merge 3 commits into
Open
Add syntax-aware enclosing definitions and folded output#3998Matei02355 wants to merge 3 commits into
Matei02355 wants to merge 3 commits into
Conversation
Matei02355
marked this pull request as ready for review
September 7, 2026 18:17
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
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.
Add --function-context/-W N to select and highlight the enclosing function, method or type, and --fold to collapse complete block interiors, multiline comments and consecutive imports/includes. Expose both operations through PrettyPrinter.
Index Syntect definition-name scopes and block punctuation before rendering, so nested control blocks and braces in comments or strings do not incorrectly establish function boundaries. Select the innermost complete function/type for each requested line; namespace-contained globals and unrecognized/incomplete constructs fall back to the selected line. Folding keeps opening and closing block lines and combines nested omissions. Existing line numbers, syntax coloring, headers and snip separators remain available.
Both modes read the complete input and are mutually exclusive with streaming mode, explicit line ranges and Git diff mode. The index covers brace-delimited definitions rather than a compiler AST; indentation-only definitions are documented as unsupported. Plain piped output contains retained source lines, while decorated snip output marks omissions. Preserve real file metadata and independently index each input. Fix UTF-16BE first-line initialization, which otherwise consumes two physical lines and shifts the rendered selection.
Validation: all 493 all-feature tests passed (7 ignored), including 20 new tests covering C, C++, Java, Objective-C, Rust, nested definitions, multiline signatures, strings/comments, globals, prototypes, incomplete constructs, repeated selections, numbering, snips, multiple files, automatic syntax detection, UTF-16LE/BE, CRLF, coloring, folding and library usage. All 8 default-feature help tests, all-target/all-feature Clippy with warnings denied, the minimal library build, formatting, whitespace checks and Bash/Zsh completion syntax passed. A subsequent adjacent-comment regression confirms that code between comments on a shared line remains visible; all 7 structural unit tests and 13 structural integration tests passed again, followed by all-target/all-feature Clippy. README, manual, help and four completions are updated.
Fixes #2228.
Fixes #3005.