summaryrefslogtreecommitdiff
path: root/lib/Format/TokenAnnotator.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-02-16 19:10:26 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-02-16 19:10:26 +0000
commit6eea8b8c1aad853d6161709d8b3035dfd867fa1c (patch)
tree195fb543fdb28a1c2a6baf81d96adc1bc302f8ca /lib/Format/TokenAnnotator.cpp
parent660d91aa9ee00f68bdb884b29845a39be78bc557 (diff)
Notes
Diffstat (limited to 'lib/Format/TokenAnnotator.cpp')
-rw-r--r--lib/Format/TokenAnnotator.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 298c72b002f8..079b330f3a7d 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -1723,15 +1723,18 @@ void TokenAnnotator::setCommentLineLevels(
}
}
- if (NextNonCommentLine && CommentLine) {
- // If the comment is currently aligned with the line immediately following
- // it, that's probably intentional and we should keep it.
- bool AlignedWithNextLine =
- NextNonCommentLine->First->NewlinesBefore <= 1 &&
- NextNonCommentLine->First->OriginalColumn ==
- (*I)->First->OriginalColumn;
- if (AlignedWithNextLine)
- (*I)->Level = NextNonCommentLine->Level;
+ // If the comment is currently aligned with the line immediately following
+ // it, that's probably intentional and we should keep it.
+ if (NextNonCommentLine && CommentLine &&
+ NextNonCommentLine->First->NewlinesBefore <= 1 &&
+ NextNonCommentLine->First->OriginalColumn ==
+ (*I)->First->OriginalColumn) {
+ // Align comments for preprocessor lines with the # in column 0.
+ // Otherwise, align with the next line.
+ (*I)->Level = (NextNonCommentLine->Type == LT_PreprocessorDirective ||
+ NextNonCommentLine->Type == LT_ImportStatement)
+ ? 0
+ : NextNonCommentLine->Level;
} else {
NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : nullptr;
}