summaryrefslogtreecommitdiffstats
path: root/tools/clang-format
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2016-08-10 09:32:23 +0000
committerEric Liu <ioeric@google.com>2016-08-10 09:32:23 +0000
commit832dfc2ae9e3bae085a9ef5c97c9d864139030e6 (patch)
tree96f0f41cef04c03741aa30174a9e50cac4c2288e /tools/clang-format
parentafb075bfdb5cafe1edb40a3508f74b56d5b6fc4b (diff)
Make clang-format remove duplicate headers when sorting #includes.
Summary: When sorting #includes, #include directives that have the same text will be deduplicated when sorting #includes, and only the first #include in the duplicate #includes remains. If the `Cursor` is provided and put on a deleted #include, it will be put on the remaining #include in the duplicate #includes. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D23274 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278206 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-format')
-rw-r--r--tools/clang-format/ClangFormat.cpp5
1 files changed, 2 insertions, 3 deletions
diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp
index 3b893e04b3..c09723928b 100644
--- a/tools/clang-format/ClangFormat.cpp
+++ b/tools/clang-format/ClangFormat.cpp
@@ -260,9 +260,8 @@ static bool format(StringRef FileName) {
llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n";
return true;
}
- for (const auto &R : Replaces)
- Ranges.push_back({R.getOffset(), R.getLength()});
-
+ // Get new affected ranges after sorting `#includes`.
+ Ranges = tooling::calculateRangesAfterReplacements(Replaces, Ranges);
bool IncompleteFormat = false;
Replacements FormatChanges = reformat(FormatStyle, *ChangedCode, Ranges,
AssumedFileName, &IncompleteFormat);