[clang-tools-extra] Fixes clangd/clangd#1797 (PR #158461)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 3 12:14:22 PST 2026


================
@@ -82,26 +82,39 @@ std::optional<Path> getCorrespondingHeaderOrSource(PathRef OriginalFile,
       Request.IDs.insert(ID);
   }
   llvm::StringMap<int> Candidates; // Target path => score.
-  auto AwardTarget = [&](const char *TargetURI) {
-    if (auto TargetPath = URI::resolve(TargetURI, OriginalFile)) {
-      if (!pathEqual(*TargetPath, OriginalFile)) // exclude the original file.
-        ++Candidates[*TargetPath];
-    } else {
-      elog("Failed to resolve URI {0}: {1}", TargetURI, TargetPath.takeError());
-    }
-  };
-  // If we switch from a header, we are looking for the implementation
-  // file, so we use the definition loc; otherwise we look for the header file,
-  // we use the decl loc;
+  // When in the implementation file, we always search for the header file,
+  // using the decl loc. When we are in a header, this usually implies searching
+  // for implementation, for which we use the definition loc. For templates, we
+  // can have separate implementation headers, which behave as an implementation
+  // file. As such, we always have to add the decl loc and conditionally
+  // definition loc.
   //
   // For each symbol in the original file, we get its target location (decl or
   // def) from the index, then award that target file.
-  const bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts());
+#ifdef CLANGD_PATH_CASE_INSENSITIVE
+  auto pathEqual = [](llvm::StringRef l, llvm::StringRef r) {
+    return l.equals_insensitive(r);
+  };
+#else
+  auto pathEqual = [](llvm::StringRef l, llvm::StringRef r) { return l == r; };
+#endif
----------------
JVApen wrote:

Makes sense, I should check why I did that. I suspect because I'm having StringRef instead of PathRef here. Though most likely I'm just using the wrong type here. To be fixed. 

https://github.com/llvm/llvm-project/pull/158461


More information about the cfe-commits mailing list