r235582 - clang-format: [Proto] Don't linewrap top-level options.
Daniel Jasper
djasper at google.com
Thu Apr 23 02:54:12 PDT 2015
Author: djasper
Date: Thu Apr 23 04:54:10 2015
New Revision: 235582
URL: http://llvm.org/viewvc/llvm-project?rev=235582&view=rev
Log:
clang-format: [Proto] Don't linewrap top-level options.
They are very similar to import statements.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=235582&r1=235581&r2=235582&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Apr 23 04:54:10 2015
@@ -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) {
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=235582&r1=235581&r2=235582&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Thu Apr 23 04:54:10 2015
@@ -105,6 +105,14 @@ TEST_F(FormatTestProto, MessageFieldAttr
"}];");
}
+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"
More information about the cfe-commits
mailing list