Skip to content

Commit

Permalink
[clang-format] Use SpacesBeforeTrailingComments for "option" directive
Browse files Browse the repository at this point in the history
Summary:
AnnotatingParser::next() is needed to implicitly set TT_BlockComment
versus TT_LineComment.  On most other paths through
AnnotatingParser::parseLine(), all tokens are consumed to achieve that.
This change updates one place where this wasn't done.

Contributed by @dchai!

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 358275
  • Loading branch information
krasimirgg committed Apr 12, 2019
1 parent 4f789e1 commit 6915046
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -1124,8 +1124,11 @@ class AnnotatingParser {
if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
CurrentToken->is(Keywords.kw_option)) {
next();
if (CurrentToken && CurrentToken->is(tok::identifier))
if (CurrentToken && CurrentToken->is(tok::identifier)) {
while (CurrentToken)
next();
return LT_ImportStatement;
}
}

bool KeywordVirtualFound = false;
Expand Down
4 changes: 4 additions & 0 deletions clang/unittests/Format/FormatTestProto.cpp
Expand Up @@ -193,6 +193,10 @@ TEST_F(FormatTestProto, DoesntWrapFileOptions) {
"\"some.really.long.package.that.exceeds.the.column.limit\";"));
}

TEST_F(FormatTestProto, TrailingCommentAfterFileOption) {
verifyFormat("option java_package = \"foo.pkg\"; // comment\n");
}

TEST_F(FormatTestProto, FormatsOptions) {
verifyFormat("option (MyProto.options) = {\n"
" field_a: OK\n"
Expand Down

0 comments on commit 6915046

Please sign in to comment.