Revert "Revert D106562 "[clangd] Get rid of arg adjusters in CommandMangler""
This reverts commit 2aa0cf19e7fe17c9eb5eb2555e10184061b933f1.
Get rid of reference to the temporary.
diff --git a/clang-tools-extra/clangd/CompileCommands.cpp b/clang-tools-extra/clangd/CompileCommands.cpp
index e749720..ffc6630 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -12,6 +12,8 @@
#include "clang/Driver/Options.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Tooling/ArgumentsAdjusters.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Debug.h"
@@ -20,6 +22,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
+#include <iterator>
#include <string>
#include <vector>
@@ -202,14 +205,9 @@
return false;
};
- // clangd should not write files to disk, including dependency files
- // requested on the command line.
- Cmd = tooling::getClangStripDependencyFileAdjuster()(Cmd, "");
- // Strip plugin related command line arguments. Clangd does
- // not support plugins currently. Therefore it breaks if
- // compiler tries to load plugins.
- Cmd = tooling::getStripPluginsAdjuster()(Cmd, "");
- Cmd = tooling::getClangSyntaxOnlyAdjuster()(Cmd, "");
+ llvm::erase_if(Cmd, [](llvm::StringRef Elem) {
+ return Elem.startswith("--save-temps") || Elem.startswith("-save-temps");
+ });
std::vector<std::string> ToAppend;
if (ResourceDir && !Has("-resource-dir"))
@@ -223,8 +221,8 @@
}
if (!ToAppend.empty()) {
- Cmd = tooling::getInsertArgumentAdjuster(
- std::move(ToAppend), tooling::ArgumentInsertPosition::END)(Cmd, "");
+ Cmd.insert(llvm::find(Cmd, "--"), std::make_move_iterator(ToAppend.begin()),
+ std::make_move_iterator(ToAppend.end()));
}
if (!Cmd.empty()) {