From: Paul Hoad Date: Sat, 23 Mar 2019 14:43:41 +0000 (+0000) Subject: [clang-format] Keep protobuf "package" statement on one line X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f5e52738fe9d991e065233b5b239ba491d76fe3b;p=platform%2Fupstream%2Fllvm.git [clang-format] Keep protobuf "package" statement on one line Summary: Top-level "package" and "import" statements should generally be kept on one line, for all languages. Reviewers: sammccall, krasimir, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: MyDeveloperDay, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59627 Patch By: dchai (Donald Chai) llvm-svn: 356835 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index ccf5e51..a3000a8 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1119,10 +1119,10 @@ public: return LT_ImportStatement; } - // In .proto files, top-level options are very similar to import statements - // and should not be line-wrapped. + // In .proto files, top-level options and package statements are very + // similar to import statements and should not be line-wrapped. if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 && - CurrentToken->is(Keywords.kw_option)) { + CurrentToken->isOneOf(Keywords.kw_option, Keywords.kw_package)) { next(); if (CurrentToken && CurrentToken->is(tok::identifier)) return LT_ImportStatement; diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp index d5683b5..fd4870c2 100644 --- a/clang/unittests/Format/FormatTestProto.cpp +++ b/clang/unittests/Format/FormatTestProto.cpp @@ -393,6 +393,12 @@ TEST_F(FormatTestProto, FormatsOptions) { "};"); } +TEST_F(FormatTestProto, DoesntWrapPackageStatements) { + verifyFormat( + "package" + " some.really.long.package.that.exceeds.the.column.limit00000000;"); +} + TEST_F(FormatTestProto, FormatsService) { verifyFormat("service SearchService {\n" " rpc Search(SearchRequest) returns (SearchResponse) {\n"