[PATCH] D83508: [clangd][Hover] Don't use Decl if it is not related with tokens under cursor.
Aleksandr Platonov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 9 14:22:59 PDT 2020
ArcsinX created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
This patch fixes redundant hover with information about Decl which is not under cursor.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D83508
Files:
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -942,6 +942,13 @@
template <typename T> void foo() {
(void)[[size^of]](T);
})cpp",
+ R"cpp(// No Decl for token under cursor.
+ namespace ns {
+ #define FOO B^AR;
+ })cpp",
+ R"cpp(//error-ok
+ unknown f(i^nt);
+ )cpp",
// literals
"auto x = t^rue;",
"auto x = '^A';",
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -820,6 +820,18 @@
SelectionTree::createRight(AST.getASTContext(), TB, Offset, Offset);
std::vector<const Decl *> Result;
if (const SelectionTree::Node *N = ST.commonAncestor()) {
+ // Don't allow Decls which are not related with tokens under cursor.
+ if (const auto *D = N->ASTNode.get<Decl>()) {
+ bool IsDeclTouchingCursor = false;
+ for (const auto &Tok : TokensTouchingCursor) {
+ if (D->getLocation() == Tok.location()) {
+ IsDeclTouchingCursor = true;
+ break;
+ }
+ }
+ if (!IsDeclTouchingCursor)
+ return llvm::None;
+ }
// FIXME: Fill in HighlightRange with range coming from N->ASTNode.
auto Decls = explicitReferenceTargets(N->ASTNode, DeclRelation::Alias);
if (!Decls.empty()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83508.276836.patch
Type: text/x-patch
Size: 1627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200709/a2c7c468/attachment.bin>
More information about the cfe-commits
mailing list