usaxena95 created this revision. usaxena95 added reviewers: hokein, kadircet. Herald added a subscriber: arphaman. usaxena95 requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
Addresses https://github.com/clangd/clangd/issues/881 Includes refs of base class method in refs of derived class method. Previously we reported base class method's refs only for decl of derived class method. Ideally this should work for all usages of derived class method. Related patch: https://github.com/llvm/llvm-project/commit/fbeff2ec2bc6e44b92931207b0063f83ff7a3b3a. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D111039 Files: clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/unittests/XRefsTests.cpp Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -1978,7 +1978,7 @@ } TEST(FindReferences, RefsToBaseMethod) { - llvm::StringRef Test = + const char *Tests[] = { R"cpp( class BaseBase { public: @@ -1997,8 +1997,25 @@ BB->[[func]](); B->[[func]](); D->[[func]](); - })cpp"; - checkFindRefs(Test, /*UseIndex=*/true); + } + )cpp", + R"cpp( + class A { + public: + virtual void [[foo]](); + }; + class B : public A { + public: + void $decl[[foo]]() override; + }; + void test(A* a, B* b) { + a->[[foo]](); + b->[[fo^o]](); + } + )cpp", + }; + for (const char *Test : Tests) + checkFindRefs(Test, /*UseIndex=*/true); } TEST(FindReferences, MainFileReferencesOnly) { Index: clang-tools-extra/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/clangd/XRefs.cpp +++ clang-tools-extra/clangd/XRefs.cpp @@ -1392,10 +1392,8 @@ // references to all overridden methods in complete type hierarchy. if (const auto *CMD = llvm::dyn_cast<CXXMethodDecl>(ND)) { if (CMD->isVirtual()) - if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) == - IdentifierAtCursor->location()) { - if (auto ID = getSymbolID(CMD)) - OverriddenBy.Subjects.insert(ID); + if (auto ID = getSymbolID(CMD)) { + OverriddenBy.Subjects.insert(ID); getOverriddenMethods(CMD, OverriddenMethods); } }
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -1978,7 +1978,7 @@ } TEST(FindReferences, RefsToBaseMethod) { - llvm::StringRef Test = + const char *Tests[] = { R"cpp( class BaseBase { public: @@ -1997,8 +1997,25 @@ BB->[[func]](); B->[[func]](); D->[[func]](); - })cpp"; - checkFindRefs(Test, /*UseIndex=*/true); + } + )cpp", + R"cpp( + class A { + public: + virtual void [[foo]](); + }; + class B : public A { + public: + void $decl[[foo]]() override; + }; + void test(A* a, B* b) { + a->[[foo]](); + b->[[fo^o]](); + } + )cpp", + }; + for (const char *Test : Tests) + checkFindRefs(Test, /*UseIndex=*/true); } TEST(FindReferences, MainFileReferencesOnly) { Index: clang-tools-extra/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/clangd/XRefs.cpp +++ clang-tools-extra/clangd/XRefs.cpp @@ -1392,10 +1392,8 @@ // references to all overridden methods in complete type hierarchy. if (const auto *CMD = llvm::dyn_cast<CXXMethodDecl>(ND)) { if (CMD->isVirtual()) - if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) == - IdentifierAtCursor->location()) { - if (auto ID = getSymbolID(CMD)) - OverriddenBy.Subjects.insert(ID); + if (auto ID = getSymbolID(CMD)) { + OverriddenBy.Subjects.insert(ID); getOverriddenMethods(CMD, OverriddenMethods); } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits