diff options
author | Daniel Jasper <djasper@google.com> | 2013-03-04 13:43:19 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-03-04 13:43:19 +0000 |
commit | 1eee6c4269af28eb4e3500de7fc39c1eb8b26aa3 (patch) | |
tree | e7f9fe5d413c438122fa3ec1186d3fb9a625b4c2 /lib/Format/Format.cpp | |
parent | e3a2b81429d935e3cfafa4c3ad1b21b957653165 (diff) |
Format a line if a range in its leading whitespace was selected.
With [] marking the selected range, clang-format invoked on
[ ] int a;
Would so far not reformat anything. With this patch, it formats a
line if its leading whitespace is touched.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176435 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r-- | lib/Format/Format.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index a3c5e503b9..f7702cbd4f 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -995,6 +995,9 @@ public: // Consume and record whitespace until we find a significant token. while (FormatTok.Tok.is(tok::unknown)) { unsigned Newlines = Text.count('\n'); + if (Newlines > 0) + FormatTok.LastNewlineOffset = + FormatTok.WhiteSpaceLength + Text.rfind('\n') + 1; unsigned EscapedNewlines = Text.count("\\\n"); FormatTok.NewlinesBefore += Newlines; FormatTok.HasUnescapedNewline |= EscapedNewlines != Newlines; @@ -1371,7 +1374,8 @@ private: const FormatToken *First = &TheLine.First.FormatTok; const FormatToken *Last = &TheLine.Last->FormatTok; CharSourceRange LineRange = CharSourceRange::getTokenRange( - First->Tok.getLocation(), Last->Tok.getLocation()); + First->WhiteSpaceStart.getLocWithOffset(First->LastNewlineOffset), + Last->Tok.getLocation()); for (unsigned i = 0, e = Ranges.size(); i != e; ++i) { if (!SourceMgr.isBeforeInTranslationUnit(LineRange.getEnd(), Ranges[i].getBegin()) && |