From d1ee17a6945e4a58161fb9b16510ee1399247c2c Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 20 Jan 2014 16:47:22 +0000 Subject: [PATCH] clang-format: Properly format custom options in protocol buffer definitions. Before: option(my_option) = "abc"; After: option (my_option) = "abc"; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199672 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 3 ++- unittests/Format/FormatTestProto.cpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index b1f414f8dd..7b2c595403 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1254,7 +1254,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, const FormatToken &Left, const FormatToken &Right) { if (Style.Language == FormatStyle::LK_Proto) { - if (Right.is(tok::l_paren) && Left.TokenText == "returns") + if (Right.is(tok::l_paren) && + (Left.TokenText == "returns" || Left.TokenText == "option")) return true; } if (Right.is(tok::hashhash)) diff --git a/unittests/Format/FormatTestProto.cpp b/unittests/Format/FormatTestProto.cpp index d102c6567c..7623e46db4 100644 --- a/unittests/Format/FormatTestProto.cpp +++ b/unittests/Format/FormatTestProto.cpp @@ -68,5 +68,10 @@ TEST_F(FormatTestProto, MessageFieldAttributes) { " [default = REALLY_REALLY_LONG_CONSTANT_VALUE];"); } +TEST_F(FormatTestProto, FormatsOptions) { + verifyFormat("option java_package = \"my.test.package\";"); + verifyFormat("option (my_custom_option) = \"abc\";"); +} + } // end namespace tooling } // end namespace clang -- 2.40.0