[PATCH] D85711: [clangd] Enforce trailing slash for remote index's project root

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 11 00:57:31 PDT 2020


kbobyrev created this revision.
kbobyrev added a reviewer: hokein.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
kbobyrev requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85711

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/remote/Client.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
@@ -702,6 +702,10 @@
     return 1;
   }
   if (!RemoteIndexAddress.empty()) {
+    if (!ProjectRoot.empty() &&
+        !llvm::StringRef(ProjectRoot)
+             .endswith(llvm::sys::path::get_separator()))
+      ProjectRoot += llvm::sys::path::get_separator();
     if (IndexFile.empty()) {
       log("Connecting to remote index at {0}", RemoteIndexAddress);
       StaticIdx = remote::getClient(RemoteIndexAddress, ProjectRoot);
Index: clang-tools-extra/clangd/index/remote/Client.cpp
===================================================================
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -76,7 +76,9 @@
       : Stub(remote::SymbolIndex::NewStub(Channel)),
         ProtobufMarshaller(new Marshaller(/*RemoteIndexRoot=*/"",
                                           /*LocalIndexRoot=*/ProjectRoot)),
-        DeadlineWaitingTime(DeadlineTime) {}
+        DeadlineWaitingTime(DeadlineTime) {
+    assert(!ProjectRoot.empty());
+  }
 
   void lookup(const clangd::LookupRequest &Request,
               llvm::function_ref<void(const clangd::Symbol &)> Callback) const {
Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===================================================================
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/Signals.h"
 
 namespace clang {
@@ -381,6 +382,10 @@
     return -1;
   }
 
+  if (!ProjectRoot.empty() &&
+      !llvm::StringRef(ProjectRoot).endswith(llvm::sys::path::get_separator()))
+    ProjectRoot += llvm::sys::path::get_separator();
+
   std::unique_ptr<SymbolIndex> Index;
   reportTime(RemoteMode ? "Remote index client creation" : "Dex build",
              [&]() { Index = openIndex(IndexLocation); });


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85711.284597.patch
Type: text/x-patch
Size: 2201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200811/1d973820/attachment.bin>


More information about the cfe-commits mailing list