kbobyrev created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay, ilya-biryukov, mgorny.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83817

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/Features.inc.in
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ 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"
@@ -64,6 +65,7 @@
 OptionCategory Features("clangd feature options");
 OptionCategory Misc("clangd miscellaneous options");
 OptionCategory Protocol("clangd protocol and logging options");
+OptionCategory Remote("clangd remote index options");
 const OptionCategory *ClangdCategories[] = {&Features, &Protocol,
                                             &CompileCommands, &Misc};
 
@@ -449,6 +451,25 @@
     init(false),
 };
 
+#ifdef CLANGD_ENABLE_REMOTE
+opt<std::string> RemoteIndexAddress{
+    "remote-index-address",
+    cat(Remote),
+    desc("Address of the remote index server"),
+    Hidden,
+};
+
+// FIXME(kirillbobyrev): This can be inferred by Clangd. Add note: requires
+// RemoteIndexAddress to be set.
+opt<std::string> ProjectPath{
+    "project-path",
+    cat(Remote),
+    // FIXME(kirillbobyrev): Add description.
+    desc(""),
+    Hidden,
+};
+#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 +701,20 @@
     if (Sync)
       AsyncIndexLoad.wait();
   }
+  if (RemoteIndexAddress.empty() != ProjectPath.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()) {
+      llvm::errs() << "When remote index is enabled, IndexFile should not be "
+                      "specified. Only one can be used at time.";
+      return 1;
+    }
+    log("Connecting to remote index at {0}", RemoteIndexAddress);
+    StaticIdx = remote::getClient(RemoteIndexAddress, ProjectPath);
+  }
   Opts.StaticIndex = StaticIdx.get();
   Opts.AsyncThreadsCount = WorkerThreadsCount;
   Opts.BuildRecoveryAST = RecoveryAST;
Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
===================================================================
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -146,8 +146,7 @@
 llvm::Optional<clangd::Symbol> fromProtobuf(const Symbol &Message,
                                             llvm::UniqueStringSaver *Strings,
                                             llvm::StringRef IndexRoot) {
-  if (!Message.has_info() || !Message.has_definition() ||
-      !Message.has_canonical_declaration()) {
+  if (!Message.has_info()) {
     elog("Cannot convert Symbol from Protobuf: {0}",
          Message.ShortDebugString());
     return llvm::None;
@@ -164,14 +163,12 @@
   Result.Name = Message.name();
   Result.Scope = Message.scope();
   auto Definition = fromProtobuf(Message.definition(), Strings, IndexRoot);
-  if (!Definition)
-    return llvm::None;
-  Result.Definition = *Definition;
+  if (Definition)
+    Result.Definition = *Definition;
   auto Declaration =
       fromProtobuf(Message.canonical_declaration(), Strings, IndexRoot);
   if (!Declaration)
-    return llvm::None;
-  Result.CanonicalDeclaration = *Declaration;
+    Result.CanonicalDeclaration = *Declaration;
   Result.References = Message.references();
   Result.Origin = static_cast<clangd::SymbolOrigin>(Message.origin());
   Result.Signature = Message.signature();
Index: clang-tools-extra/clangd/Features.inc.in
===================================================================
--- clang-tools-extra/clangd/Features.inc.in
+++ clang-tools-extra/clangd/Features.inc.in
@@ -1 +1,2 @@
 #define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
+#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMTE@
Index: clang-tools-extra/clangd/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -109,6 +109,15 @@
   omp_gen
   )
 
+# FIXME(kirillbobyrev): Document this in the LLVM docs once remote index is stable.
+option(CLANGD_ENABLE_REMOTE "Use gRPC library to enable remote index support for Clangd" OFF)
+set(GRPC_INSTALL_PATH "" CACHE PATH "Path to gRPC library manual installation.")
+
+if (CLANGD_ENABLE_REMOTE)
+  include(FindGRPC)
+endif()
+add_subdirectory(index/remote)
+
 clang_target_link_libraries(clangDaemon
   PRIVATE
   clangAST
@@ -126,6 +135,7 @@
   clangToolingInclusions
   clangToolingRefactoring
   clangToolingSyntax
+  clangdRemoteIndex
   )
 
 add_subdirectory(refactor/tweaks)
@@ -148,12 +158,4 @@
 add_subdirectory(unittests)
 endif()
 
-# FIXME(kirillbobyrev): Document this in the LLVM docs once remote index is stable.
-option(CLANGD_ENABLE_REMOTE "Use gRPC library to enable remote index support for Clangd" OFF)
-set(GRPC_INSTALL_PATH "" CACHE PATH "Path to gRPC library manual installation.")
-
-if (CLANGD_ENABLE_REMOTE)
-  include(FindGRPC)
-endif()
-add_subdirectory(index/remote)
 add_subdirectory(index/dex/dexp)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to