clang-format: [Proto] Don't linewrap top-level options.

They are very similar to import statements.

llvm-svn: 235582
This commit is contained in:
Daniel Jasper 2015-04-23 09:54:10 +00:00
parent 3658f6fcc4
commit 1b998815a0
2 changed files with 18 additions and 2 deletions

View File

@ -637,9 +637,8 @@ private:
public:
LineType parseLine() {
if (CurrentToken->is(tok::hash)) {
if (CurrentToken->is(tok::hash))
return parsePreprocessorDirective();
}
// Directly allow to 'import <string-literal>' to support protocol buffer
// definitions (code.google.com/p/protobuf) or missing "#" (either way we
@ -663,6 +662,15 @@ public:
return LT_ImportStatement;
}
// In .proto files, top-level options 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)) {
next();
if (CurrentToken && CurrentToken->is(tok::identifier))
return LT_ImportStatement;
}
bool KeywordVirtualFound = false;
bool ImportStatement = false;
while (CurrentToken) {

View File

@ -105,6 +105,14 @@ TEST_F(FormatTestProto, MessageFieldAttributes) {
"}];");
}
TEST_F(FormatTestProto, DoesntWrapFileOptions) {
EXPECT_EQ(
"option java_package = "
"\"some.really.long.package.that.exceeds.the.column.limit\";",
format("option java_package = "
"\"some.really.long.package.that.exceeds.the.column.limit\";"));
}
TEST_F(FormatTestProto, FormatsOptions) {
verifyFormat("option (MyProto.options) = {\n"
" field_a: OK\n"