Skip to content

Commit 4dea137

Browse files
committed
Revert "Revert "[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. ---- This reverts commit rL356912. The regression from rL356835 was fixed via rC358275. Reviewers: krasimir, sammccall, MyDeveloperDay, xinz, dchai, klimek Reviewed By: krasimir, xinz, dchai Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60661 llvm-svn: 360411
1 parent a2d876c commit 4dea137

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,10 +1119,10 @@ class AnnotatingParser {
11191119
return LT_ImportStatement;
11201120
}
11211121

1122-
// In .proto files, top-level options are very similar to import statements
1123-
// and should not be line-wrapped.
1122+
// In .proto files, top-level options and package statements are very
1123+
// similar to import statements and should not be line-wrapped.
11241124
if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
1125-
CurrentToken->is(Keywords.kw_option)) {
1125+
CurrentToken->isOneOf(Keywords.kw_option, Keywords.kw_package)) {
11261126
next();
11271127
if (CurrentToken && CurrentToken->is(tok::identifier)) {
11281128
while (CurrentToken)

clang/unittests/Format/FormatTestProto.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,16 @@ TEST_F(FormatTestProto, FormatsOptions) {
397397
"};");
398398
}
399399

400+
TEST_F(FormatTestProto, DoesntWrapPackageStatements) {
401+
verifyFormat(
402+
"package"
403+
" some.really.long.package.that.exceeds.the.column.limit00000000;");
404+
}
405+
406+
TEST_F(FormatTestProto, TrailingCommentAfterPackage) {
407+
verifyFormat("package foo.pkg; // comment\n");
408+
}
409+
400410
TEST_F(FormatTestProto, FormatsService) {
401411
verifyFormat("service SearchService {\n"
402412
" rpc Search(SearchRequest) returns (SearchResponse) {\n"

0 commit comments

Comments
 (0)