- Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang-format] Break the line within @selector #164674
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
Conversation
after, with style `{ColumnLimit: 60}` ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)]; ``` before ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)]; ``` Fixes llvm#164574. The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines. | @llvm/pr-subscribers-clang-format Author: None (sstwcw) Changesafter, with style [objectName respondsToSelector: @<!-- -->selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)];before [objectName respondsToSelector: @<!-- -->selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)];Fixes #164574. The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines. Full diff: https://github.com/llvm/llvm-project/pull/164674.diff 2 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c97a9e81eb59e..1d0dfd0b9c151 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -4407,8 +4407,12 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, // breaking after it. if (Right.is(TT_SelectorName)) return 0; - if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr)) - return Line.MightBeFunctionDecl ? 50 : 500; + if (Left.is(tok::colon)) { + if (Left.is(TT_ObjCMethodExpr)) + return Line.MightBeFunctionDecl ? 50 : 500; + if (Left.is(TT_ObjCSelector)) + return 500; + } // In Objective-C type declarations, avoid breaking after the category's // open paren (we'll prefer breaking after the protocol list's opening @@ -6291,7 +6295,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, TT_BitFieldColon)) { return false; } - if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) { + if (Left.is(tok::colon) && Left.isOneOf(TT_ObjCSelector, TT_ObjCMethodExpr)) + return true; + if (Left.is(tok::colon) && Left.is(TT_DictLiteral)) { if (Style.isProto()) { if (!Style.AlwaysBreakBeforeMultilineStrings && Right.isStringLiteral()) return false; diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp index 700d7cf8efca6..cf8143ace7b45 100644 --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -949,6 +949,12 @@ TEST_F(FormatTestObjC, FormatObjCMethodExpr) { "[aaaaaaaaaaaaaaaaaaaaaaaaa\n" " aaaaaaaaaaaaaaaaa:aaaaaaaa\n" " aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];"); + verifyFormat("[objectName\n" + " respondsToSelector:\n" + " @selector(\n" + " somelonglonglonglongnameeeeeeee:\n" + " loooooooooanotherlonglonglonglongnametopush:\n" + " otherlongnameforlimit:)];"); Style = getChromiumStyle(FormatStyle::LK_ObjC); Style.ColumnLimit = 80; |
| LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/181/builds/30394 Here is the relevant piece of the build log for the reference |
after, with style `{ColumnLimit: 60}` ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)]; ``` before ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)]; ``` Fixes llvm#164574. The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines. after, with style `{ColumnLimit: 60}` ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)]; ``` before ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)]; ``` Fixes llvm#164574. The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines. after, with style `{ColumnLimit: 60}` ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)]; ``` before ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)]; ``` Fixes llvm#164574. The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines.
after, with style
{ColumnLimit: 60}before
Fixes #164574.
The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines.