[PATCH] D78784: [clangd] Add some logging to explain why textual fallback navigation failed

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 23 20:07:05 PDT 2020


nridge created this revision.
nridge added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
nridge added a comment.

Applies on top of D76451 <https://reviews.llvm.org/D76451>.


Depends on D76451 <https://reviews.llvm.org/D76451>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78784

Files:
  clang-tools-extra/clangd/XRefs.cpp


Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -351,13 +351,25 @@
 locateSymbolTextually(const SpelledWord &Word, ParsedAST &AST,
                       const SymbolIndex *Index, const std::string &MainFilePath,
                       ASTNodeKind NodeKind) {
+  if (!Index)
+    return {};
+
   // Don't use heuristics if this is a real identifier, or not an
   // identifier.
   // Exception: dependent names, because those may have useful textual
   // matches that AST-based heuristics cannot find.
-  if ((Word.ExpandedToken && !isDependentName(NodeKind)) ||
-      !Word.LikelyIdentifier || !Index)
+  if (Word.ExpandedToken && !isDependentName(NodeKind)) {
+    vlog("Textual navigation: word {0} under cursor is a real token and not "
+         "dependent",
+         Word.Text);
     return {};
+  }
+  if (!Word.LikelyIdentifier) {
+    vlog("Textual navigation: word {0} under cursor is unlikely to be an "
+         "identifier",
+         Word.Text);
+    return {};
+  }
   // We don't want to handle words in string literals. It'd be nice to whitelist
   // comments instead, but they're not retained in TokenBuffer.
   if (Word.PartOfSpelledToken &&
@@ -415,6 +427,8 @@
       // If we have more than 3 results, don't return anything,
       // as confidence is too low.
       // FIXME: Alternatively, try a stricter query?
+      vlog("Textual navigation: more than 3 matching index results, confidence "
+           "is too low");
       TooMany = true;
       return;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78784.259791.patch
Type: text/x-patch
Size: 1638 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200424/2ccbb679/attachment-0001.bin>


More information about the cfe-commits mailing list