[clang-tools-extra] Fixes clangd/clangd#1797 (PR #158461)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 16 00:48:21 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
Index->lookup(Request, [&](const Symbol &Sym) {
- if (IsHeader)
- AwardTarget(Sym.Definition.FileURI);
- else
- AwardTarget(Sym.CanonicalDeclaration.FileURI);
+ if (llvm::StringRef{Sym.Definition.FileURI}.empty() ||
----------------
kadircet wrote:
why not keep the old logic, but simply call `AwardTarget` on both definition and declaration uri ? we're always excluding the original file anyways.
also in the current logic, you're trying to limit counting only for the cases where at least declaration or definition is within the `OriginalFile`, which I believe makes sense. but is an orthogonal change to what you're doing here. can you move that into a separate change (if you think that's needed)?
https://github.com/llvm/llvm-project/pull/158461
More information about the cfe-commits
mailing list