Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add equivalent of LambdaBodyIndentation for ObjC blocks #53740

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
jrose-signal opened this issue Feb 11, 2022 · 5 comments
Open

Add equivalent of LambdaBodyIndentation for ObjC blocks #53740

jrose-signal opened this issue Feb 11, 2022 · 5 comments
Assignees
Labels
clang-format good first issue https://github.com/llvm/llvm-project/contribute objective-c

Comments

@jrose-signal
Copy link

With the attached clang-format file, the following (mildly reduced) Objective-C snippet formats as displayed:

- (void)test
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        do {
            DatabaseStorageWrite(self.databaseStorage, ^(SDSAnyWriteTransaction *transaction) {
                [interactionFinder enumerateUnreadMessagesBeforeSortId:sortId
                                                           transaction:transaction.unwrapGrdbWrite
                                                                 block:^(id<OWSReadTracking> readItem, BOOL *stop) {
                                                                     [readItem markAsReadAtTimestamp:readTimestamp
                                                                                              thread:thread
                                                                                        circumstance:circumstance
                                                                                         transaction:transaction];
                                                                     --batchQuotaRemaining;
                                                                     if (batchQuotaRemaining == 0) {
                                                                         *stop = true;
                                                                     }
                                                                 }];
            });
        } while (batchQuotaRemaining == 0);
    });
}

when I would like it to format as

- (void)test
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        do {
            batchQuotaRemaining = maxBatchSize;
            DatabaseStorageWrite(self.databaseStorage, ^(SDSAnyWriteTransaction *transaction) {
                [interactionFinder enumerateUnreadMessagesBeforeSortId:sortId
                                                           transaction:transaction.unwrapGrdbWrite
                                                                 block:^(id<OWSReadTracking> readItem, BOOL *stop) {
                    [readItem markAsReadAtTimestamp:readTimestamp
                                             thread:thread
                                       circumstance:circumstance
                                        transaction:transaction];
                    --batchQuotaRemaining;
                    if (batchQuotaRemaining == 0) {
                        *stop = true;
                    }
                }];
            });
        } while (batchQuotaRemaining == 0);
    });

which is what Xcode does. This seems equivalent to LambdaBodyIndentation, but there's no equivalent setting for ObjC blocks.

@EugeneZelenko EugeneZelenko added clang-format enhancement Improving things as opposed to bug fixing, e.g. new or missing feature and removed new issue labels Feb 11, 2022
@llvmbot
Copy link
Member

llvmbot commented Feb 11, 2022

@llvm/issue-subscribers-clang-format

@mkurdej
Copy link
Member

mkurdej commented Feb 11, 2022

Indeed what you ask for is analogous to LambdaBodyIndentation.
There's already ObjCBlockIndentWidth, so I think that adding ObjCBlockBodyIndentation is worth doing.
It should be pretty straightforward to mimic LambdaBodyIndentation.

PRs welcome!

@mkurdej mkurdej added the good first issue https://github.com/llvm/llvm-project/contribute label Feb 11, 2022
@chaitanyav chaitanyav self-assigned this Apr 25, 2023
@chaitanyav
Copy link
Contributor

@mkurdej i will work on this.

@jaredgrubb
Copy link
Contributor

@mkurdej you're my hero!

@owenca owenca removed the enhancement Improving things as opposed to bug fixing, e.g. new or missing feature label Mar 3, 2025
@triplef
Copy link
Member

triplef commented May 5, 2025

Would love to see this as well! @chaitanyav did you get anywhere with the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format good first issue https://github.com/llvm/llvm-project/contribute objective-c
Projects
None yet
Development

No branches or pull requests

8 participants