[clang-tools-extra] 37ac559 - [clangd] Add option to use remote index as static index
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 27 02:24:26 PDT 2020
Author: Kirill Bobyrev
Date: 2020-07-27T11:24:15+02:00
New Revision: 37ac559fccd46dcec246ceb3907c8d3910728c69
URL: https://github.com/llvm/llvm-project/commit/37ac559fccd46dcec246ceb3907c8d3910728c69
DIFF: https://github.com/llvm/llvm-project/commit/37ac559fccd46dcec246ceb3907c8d3910728c69.diff
LOG: [clangd] Add option to use remote index as static index
Reviewers: hokein
Reviewed By: hokein
Subscribers: usaxena95, mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D83817
Added:
Modified:
clang-tools-extra/clangd/Features.inc.in
clang-tools-extra/clangd/tool/CMakeLists.txt
clang-tools-extra/clangd/tool/ClangdMain.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Features.inc.in b/clang-tools-extra/clangd/Features.inc.in
index da75aa67a65b..8584b87c6205 100644
--- a/clang-tools-extra/clangd/Features.inc.in
+++ b/clang-tools-extra/clangd/Features.inc.in
@@ -1 +1,2 @@
#define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
+#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMTE@
diff --git a/clang-tools-extra/clangd/tool/CMakeLists.txt b/clang-tools-extra/clangd/tool/CMakeLists.txt
index 3368013f5079..670e5a17013a 100644
--- a/clang-tools-extra/clangd/tool/CMakeLists.txt
+++ b/clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -27,6 +27,7 @@ clang_target_link_libraries(clangd
clangToolingCore
clangToolingRefactoring
clangToolingSyntax
+ clangdRemoteIndex
)
target_link_libraries(clangd
PRIVATE
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 7bce1c062e81..8d1bf5c42260 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -14,6 +14,7 @@
#include "Transport.h"
#include "index/Background.h"
#include "index/Serialization.h"
+#include "index/remote/Client.h"
#include "refactor/Rename.h"
#include "support/Path.h"
#include "support/Shutdown.h"
@@ -449,6 +450,21 @@ opt<bool> EnableConfig{
init(true),
};
+#ifdef CLANGD_ENABLE_REMOTE
+opt<std::string> RemoteIndexAddress{
+ "remote-index-address",
+ cat(Features),
+ desc("Address of the remote index server"),
+};
+
+// FIXME(kirillbobyrev): Should this be the location of compile_commands.json?
+opt<std::string> ProjectRoot{
+ "project-root",
+ cat(Features),
+ desc("Path to the project root. Requires remote-index-address to be set."),
+};
+#endif
+
/// Supports a test URI scheme with relaxed constraints for lit tests.
/// The path in a test URI will be combined with a platform-specific fake
/// directory to form an absolute path. For example, test:///a.cpp is resolved
@@ -680,6 +696,23 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
if (Sync)
AsyncIndexLoad.wait();
}
+#ifdef CLANGD_ENABLE_REMOTE
+ if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
+ llvm::errs() << "remote-index-address and project-path have to be "
+ "specified at the same time.";
+ return 1;
+ }
+ if (!RemoteIndexAddress.empty()) {
+ if (IndexFile.empty()) {
+ log("Connecting to remote index at {0}", RemoteIndexAddress);
+ StaticIdx = remote::getClient(RemoteIndexAddress, ProjectRoot);
+ EnableBackgroundIndex = false;
+ } else {
+ elog("When enabling remote index, IndexFile should not be specified. "
+ "Only one can be used at time. Remote index will ignored.");
+ }
+ }
+#endif
Opts.StaticIndex = StaticIdx.get();
Opts.AsyncThreadsCount = WorkerThreadsCount;
Opts.BuildRecoveryAST = RecoveryAST;
More information about the cfe-commits
mailing list