什么clang-format选项控制方法调用参数的格式?

Aar*_*her 18 formatting objective-c clang clang-format

我知道人们对如何在Objective-C中格式化方法调用有不同的看法,即

[self presentViewController:scanViewController
                   animated:YES
                 completion:nil];
Run Code Online (Sandbox Code Playgroud)

VS

[self presentViewController:scanViewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

我使用.clang格式文件中的哪些选项来控制这种缩进?(如果我不想要它,冒号排队等)

还有,这只是我还是这个格式无知的块?注意成功块的if语句不是缩进的,NSLog函数也不是故障块.

[self.client getPath:path
    parameters:parameters
    success:^(AFHTTPRequestOperation *operation, id responseObject) {
    if ([from_id isEqualToString:self.from_id]) {
        self.image.image = [UIImage imageWithData:responseObject];
    }
    }
    failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(error.description);
    }];
Run Code Online (Sandbox Code Playgroud)

Mat*_*ias 10

我查看了clang格式的源代码,其中Objective-c方法表达式的格式化完成并在此处找到:http://llvm.org/svn/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp

代码:

// If this '[' opens an ObjC call, determine whether all parameters fit
// into one line and put one per line if they don't.
if (Current.Type == TT_ObjCMethodExpr &&
    getLengthToMatchingParen(Current) + State.Column >
        getColumnLimit(State))
  BreakBeforeParameter = true;
Run Code Online (Sandbox Code Playgroud)

如您所见,行为仅由配置选项ColumnLimit控制.您可以将其设置为0以抑制换行符.不幸的是,这当然影响了完整的格式.

关于块内缺少缩进的问题:我无法使用最新的Visual Studio插件(SVN r203967)重现它.你有没有摆弄ContinuationIndentWidth?

  • 我已经将ColumnLimit设置为0并且我正在使用带有插件的Xcode在使用.clang格式文件进行保存时进行格式化. (2认同)
  • 这最近改变了铿锵格式3.7?将ColumnLimit设置为0对我来说停止了工作,我很生气,因为它工作得很好!:D将ColumnLimit设置为1000也不起作用!还有其他方法吗? (2认同)