]> granicus.if.org Git - clang/commitdiff
[clang-format] Use SpacesBeforeTrailingComments for "option" directive
authorKrasimir Georgiev <krasimir@google.com>
Fri, 12 Apr 2019 10:11:34 +0000 (10:11 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Fri, 12 Apr 2019 10:11:34 +0000 (10:11 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358275 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestProto.cpp

index 032be722b28616073bf51690c1750efbd5b057bb..ddaacaab777511f38e7ff758db2077353ac4ab71 100644 (file)
@@ -1124,8 +1124,11 @@ public:
     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;
index d5683b5b844fb8905546f46f574d758ab06a8017..ac042316bc29140160a5b6082ad1a9b109362f65 100644 (file)
@@ -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"