[clang-format] Recognize percents as format specifiers in protos

Summary:
Frequently, a percent in protos denotes a formatting specifier for string replacement.
Thus it is desirable to keep the percent together with what follows after it.

Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D43294

llvm-svn: 325159
This commit is contained in:
Krasimir Georgiev 2018-02-14 19:47:58 +00:00
parent ab31b7759d
commit 76064a4b1e
3 changed files with 13 additions and 0 deletions

View File

@ -2425,6 +2425,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) &&
Right.isOneOf(tok::l_brace, tok::less))
return !Style.Cpp11BracedListStyle;
// A percent is probably part of a formatting specification, such as %lld.
if (Left.is(tok::percent))
return false;
} else if (Style.Language == FormatStyle::LK_JavaScript) {
if (Left.is(TT_JsFatArrow))
return true;

View File

@ -432,5 +432,11 @@ TEST_F(FormatTestProto, FormatsOptionsExtensions) {
"};");
}
TEST_F(FormatTestProto, NoSpaceAfterPercent) {
verifyFormat("option (MyProto.options) = {\n"
" key: %lld\n"
"};");
}
} // end namespace tooling
} // end namespace clang

View File

@ -386,5 +386,9 @@ TEST_F(FormatTestTextProto, FormatsExtensions) {
" }\n"
"}");
}
TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
verifyFormat("key: %d");
}
} // end namespace tooling
} // end namespace clang