[PATCH] D96844: [clangd] Pass file when possible to resolve URI.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 16 23:43:54 PST 2021


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

Some URI scheme needs the hint path to do a correct resolution, we pass
one of the open files as hint path.

This is not perfect, and it might not work for opening files across
project, but it would fix a bug with our internal scheme.

in the long run, removing URIs from all the index internals is a more proper fix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96844

Files:
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/dex/Dex.cpp


Index: clang-tools-extra/clangd/index/dex/Dex.cpp
===================================================================
--- clang-tools-extra/clangd/index/dex/Dex.cpp
+++ clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -316,9 +316,11 @@
 llvm::unique_function<IndexContents(llvm::StringRef) const>
 Dex::indexedFiles() const {
   return [this](llvm::StringRef FileURI) {
-    auto Path = URI::resolve(FileURI);
+    if (Files.empty())
+      return IndexContents::None;
+    auto Path = URI::resolve(FileURI, Files.begin()->first());
     if (!Path) {
-      llvm::consumeError(Path.takeError());
+      vlog("Failed to resolve the URI {0} : {1}", FileURI, Path.takeError());
       return IndexContents::None;
     }
     return Files.contains(*Path) ? IdxContents : IndexContents::None;
Index: clang-tools-extra/clangd/index/MemIndex.cpp
===================================================================
--- clang-tools-extra/clangd/index/MemIndex.cpp
+++ clang-tools-extra/clangd/index/MemIndex.cpp
@@ -112,9 +112,11 @@
 llvm::unique_function<IndexContents(llvm::StringRef) const>
 MemIndex::indexedFiles() const {
   return [this](llvm::StringRef FileURI) {
-    auto Path = URI::resolve(FileURI);
+    if (Files.empty())
+      return IndexContents::None;
+    auto Path = URI::resolve(FileURI, Files.begin()->first());
     if (!Path) {
-      llvm::consumeError(Path.takeError());
+      vlog("Failed to resolve the URI {0} : {1}", FileURI, Path.takeError());
       return IndexContents::None;
     }
     return Files.contains(*Path) ? IdxContents : IndexContents::None;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96844.324202.patch
Type: text/x-patch
Size: 1578 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210217/175fd192/attachment.bin>


More information about the cfe-commits mailing list