[clang-tools-extra] bd1013a - [clangd] Enforce trailing slash for remote index's project root

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 11 04:24:58 PDT 2020


Author: Kirill Bobyrev
Date: 2020-08-11T13:24:43+02:00
New Revision: bd1013a4825bf2cf58b3c75320f64b24b244f343

URL: https://github.com/llvm/llvm-project/commit/bd1013a4825bf2cf58b3c75320f64b24b244f343
DIFF: https://github.com/llvm/llvm-project/commit/bd1013a4825bf2cf58b3c75320f64b24b244f343.diff

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

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85711

Added: 
    

Modified: 
    clang-tools-extra/clangd/index/remote/Client.cpp
    clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/index/remote/Client.cpp b/clang-tools-extra/clangd/index/remote/Client.cpp
index 4c1741e715a5..131e4c0b2fce 100644
--- a/clang-tools-extra/clangd/index/remote/Client.cpp
+++ b/clang-tools-extra/clangd/index/remote/Client.cpp
@@ -76,7 +76,9 @@ class IndexClient : public clangd::SymbolIndex {
       : 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 {

diff  --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index dbda5bf24aa3..cfc72ce87be6 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -59,14 +59,16 @@ Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
     assert(llvm::sys::path::is_absolute(RemoteIndexRoot));
     assert(RemoteIndexRoot ==
            llvm::sys::path::convert_to_slash(RemoteIndexRoot));
-    assert(RemoteIndexRoot.endswith(llvm::sys::path::get_separator()));
     this->RemoteIndexRoot = RemoteIndexRoot.str();
+    if (!RemoteIndexRoot.endswith(llvm::sys::path::get_separator()))
+      *this->RemoteIndexRoot += llvm::sys::path::get_separator();
   }
   if (!LocalIndexRoot.empty()) {
     assert(llvm::sys::path::is_absolute(LocalIndexRoot));
     assert(LocalIndexRoot == llvm::sys::path::convert_to_slash(LocalIndexRoot));
-    assert(LocalIndexRoot.endswith(llvm::sys::path::get_separator()));
     this->LocalIndexRoot = LocalIndexRoot.str();
+    if (!LocalIndexRoot.endswith(llvm::sys::path::get_separator()))
+      *this->LocalIndexRoot += llvm::sys::path::get_separator();
   }
   assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty());
 }


        


More information about the cfe-commits mailing list