diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 032be722b286..ddaacaab7775 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp index d5683b5b844f..ac042316bc29 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"