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; }
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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits