Improve lambda signature detection and Qt access macro support#2
Open
imakris wants to merge 2 commits into
Open
Improve lambda signature detection and Qt access macro support#2imakris wants to merge 2 commits into
imakris wants to merge 2 commits into
Conversation
Merge lambda_body_needs_sibling_indent_normalization into normalize_lambda_body_sibling_indent so root indents are collected in the same pass that rewrites them; fold the two *_complete_lambda_signature variants into one helper that scans a caller-supplied window. Tighten is_access_label's set literal. Net effect: -54 lines, no behavior change. All 317 tests still pass.
Per author guidance on the edge cases surfaced after the prior commit:
* Skip comment-only lines while walking back from a stand-alone body
brace, so a '// note' between '-> ret' and '{' no longer breaks
detection.
* Replace the heuristic 5-line scan cap in complete_lambda_signature
with proper bracket matching: locate the capture list's ']', then
walk back through its '['/']' pairs (string/char/comment aware) and
validate the prefix and suffix look like a lambda. This also rejects
array-indexing patterns such as 'values[i]\n{' that the old
heuristic could match by coincidence.
* Extend is_access_label to cover the Qt macro forms 'Q_SIGNALS:',
'Q_SLOTS:' and 'public/protected/private Q_SLOTS:'.
Add tests for the four cases. All 321 tests pass.
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.
Summary
This PR enhances the hanging indent fixer to better handle complex lambda signatures and adds support for Qt-specific access macros. The changes improve the robustness of lambda detection by properly handling comments between signature and body, and correctly identifying lambda captures across multiple lines.
Key Changes
Enhanced lambda signature detection: Replaced two separate functions (
stripped_lines_complete_lambda_signatureandprevious_lines_complete_lambda_signature) with a unifiedcomplete_lambda_signature()function that:iter_brackets_outside_strings()utilityNew utility functions:
is_comment_only_line(): Identifies lines that contain only comments (single-line//or block/* */)iter_brackets_outside_strings(): Safely iterates over brackets while respecting string literals, character literals, and commentsfind_matching_capture_open(): Walks backward to find the opening bracket of a lambda capture, handling nested bracketsQt macro support: Extended
is_access_label()to recognize Qt-specific access macros:Q_SIGNALS:andQ_SLOTS:public Q_SLOTS:,protected Q_SLOTS:,private Q_SLOTS:Refactored indent normalization: Consolidated
lambda_body_needs_sibling_indent_normalization()logic intonormalize_lambda_body_sibling_indent()to avoid duplicate traversal and improve efficiencyImproved robustness: The new implementation correctly handles edge cases like:
values[0]) followed by blocks (not mistaken for lambdas)Test Coverage
Added comprehensive test cases covering:
https://claude.ai/code/session_01Qem2GwtMxGuSDDjK7gQpvG