diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/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; }