aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Tooling/Refactoring.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-05-21 12:21:39 +0000
committerDaniel Jasper <djasper@google.com>2013-05-21 12:21:39 +0000
commit2a250b8b49e70f53b185749a94956d54d941ef2d (patch)
treedf02c858d099e0982459b90d2f0d9715ee1b05b1 /clang/lib/Tooling/Refactoring.cpp
parentc787d42f40a6e4a8ee5c2d1a910b393b7191fdfa (diff)
downloadllvm-2a250b8b49e70f53b185749a94956d54d941ef2d.zip
llvm-2a250b8b49e70f53b185749a94956d54d941ef2d.tar.gz
llvm-2a250b8b49e70f53b185749a94956d54d941ef2d.tar.bz2
Let clang-format move the cursor appropriately.
With this patch, clang-format will try to keep the cursor at the original code position in editor integrations (implemented for emacs and vim). This means, after formatting, clang-format will try to keep the cursor on the same character of the same token. llvm-svn: 182373
Diffstat (limited to 'clang/lib/Tooling/Refactoring.cpp')
-rw-r--r--clang/lib/Tooling/Refactoring.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Tooling/Refactoring.cpp b/clang/lib/Tooling/Refactoring.cpp
index f795def..db68f42 100644
--- a/clang/lib/Tooling/Refactoring.cpp
+++ b/clang/lib/Tooling/Refactoring.cpp
@@ -166,6 +166,19 @@ std::string applyAllReplacements(StringRef Code, Replacements &Replaces) {
return Result;
}
+unsigned shiftedCodePosition(const Replacements &Replaces, unsigned Position) {
+ unsigned NewPosition = Position;
+ for (Replacements::iterator I = Replaces.begin(), E = Replaces.end(); I != E;
+ ++I) {
+ if (I->getOffset() >= Position)
+ break;
+ if (I->getOffset() + I->getLength() > Position)
+ NewPosition += I->getOffset() + I->getLength() - Position;
+ NewPosition += I->getReplacementText().size() - I->getLength();
+ }
+ return NewPosition;
+}
+
RefactoringTool::RefactoringTool(const CompilationDatabase &Compilations,
ArrayRef<std::string> SourcePaths)
: ClangTool(Compilations, SourcePaths) {}