diff options
author | Krasimir Georgiev <krasimir@google.com> | 2018-06-25 11:08:24 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2018-06-25 11:08:24 +0000 |
commit | 0895f5e8b9dcf223838bec5e9a07d4a1c6a53e59 (patch) | |
tree | b73c11805c126ed0b439e430fc2a653f2b60a894 /clang/lib/Format/UnwrappedLineParser.cpp | |
parent | c1cc3173d3d077ba10628a7538b4d65ad2bf859d (diff) | |
download | bcm5719-llvm-0895f5e8b9dcf223838bec5e9a07d4a1c6a53e59.tar.gz bcm5719-llvm-0895f5e8b9dcf223838bec5e9a07d4a1c6a53e59.zip |
[clang-format] Fix end-of-file comments text proto formatting
Summary:
The case of end-of-file comments was formatted badly:
```
key: value
# end-of-file comment
```
This patch fixes that formatting:
```
key: value
# end-of-file comment
```
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D48539
llvm-svn: 335449
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index e1fa72e84bd..e5afa1264ab 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -303,6 +303,18 @@ void UnwrappedLineParser::parseFile() { else parseLevel(/*HasOpeningBrace=*/false); // Make sure to format the remaining tokens. + // + // LK_TextProto is special since its top-level is parsed as the body of a + // braced list, which does not necessarily have natural line separators such + // as a semicolon. Comments after the last entry that have been determined to + // not belong to that line, as in: + // key: value + // // endfile comment + // do not have a chance to be put on a line of their own until this point. + // Here we add this newline before end-of-file comments. + if (Style.Language == FormatStyle::LK_TextProto && + !CommentsBeforeNextToken.empty()) + addUnwrappedLine(); flushComments(true); addUnwrappedLine(); } |