From 69150467b098322253627641f55ffeeafbcc32e4 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Fri, 12 Apr 2019 10:11:34 +0000 Subject: [PATCH] [clang-format] Use SpacesBeforeTrailingComments for "option" directive 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 --- clang/lib/Format/TokenAnnotator.cpp | 5 ++++- clang/unittests/Format/FormatTestProto.cpp | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 032be722b2861..ddaacaab77751 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp index d5683b5b844fb..ac042316bc291 100644 --- a/clang/unittests/Format/FormatTestProto.cpp +++ b/clang/unittests/Format/FormatTestProto.cpp @@ -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"