Skip to content

Improve lambda signature detection and Qt access macro support#2

Open
imakris wants to merge 2 commits into
masterfrom
claude/simplify-refactor-code-IOG1O
Open

Improve lambda signature detection and Qt access macro support#2
imakris wants to merge 2 commits into
masterfrom
claude/simplify-refactor-code-IOG1O

Conversation

@imakris

@imakris imakris commented May 12, 2026

Copy link
Copy Markdown
Member

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_signature and previous_lines_complete_lambda_signature) with a unified complete_lambda_signature() function that:

    • Properly handles comment-only lines as transparent (they don't break signature detection)
    • Correctly matches opening and closing brackets in lambda captures using a new iter_brackets_outside_strings() utility
    • Validates that lambda captures are properly preceded and followed by valid tokens
    • Extends the lookback window from 5 to 30 lines to handle long multiline captures
  • New 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 comments
    • find_matching_capture_open(): Walks backward to find the opening bracket of a lambda capture, handling nested brackets
  • Qt macro support: Extended is_access_label() to recognize Qt-specific access macros:

    • Q_SIGNALS: and Q_SLOTS:
    • public Q_SLOTS:, protected Q_SLOTS:, private Q_SLOTS:
  • Refactored indent normalization: Consolidated lambda_body_needs_sibling_indent_normalization() logic into normalize_lambda_body_sibling_indent() to avoid duplicate traversal and improve efficiency

  • Improved robustness: The new implementation correctly handles edge cases like:

    • Comments between lambda signature and opening brace
    • Array indexing (e.g., values[0]) followed by blocks (not mistaken for lambdas)
    • Long multiline lambda captures with proper indentation repair

Test Coverage

Added comprehensive test cases covering:

  • Comments between lambda signature and body brace
  • Long multiline captures with body indent repair
  • Array indexing not mistaken for lambda captures
  • Qt access macros inside lambda bodies

https://claude.ai/code/session_01Qem2GwtMxGuSDDjK7gQpvG

claude added 2 commits May 12, 2026 21:42
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants