From 283b6dec8d08520f73ebd4563966f491b49d47b2 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Mon, 26 Sep 2022 04:17:27 +0200 Subject: [PATCH] [clangd] Make go-to-type work on member function calls --- clang-tools-extra/clangd/FindTarget.cpp | 4 ++++ clang-tools-extra/clangd/XRefs.cpp | 6 ++++++ clang-tools-extra/clangd/unittests/XRefsTests.cpp | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp index 020f83b1a8fb..17be646c7d7c 100644 --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -454,6 +454,10 @@ public: Outer.add(TD->getTemplatedDecl(), Flags | Rel::TemplatePattern); } } + void + VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *STTPT) { + Outer.add(STTPT->getReplacementType(), Flags); + } void VisitTemplateTypeParmType(const TemplateTypeParmType *TTPT) { Outer.add(TTPT->getDecl(), Flags); } diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index 25ddcbdbd739..10fb14b2ba8c 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -1834,6 +1834,12 @@ static QualType typeForNode(const SelectionTree::Node *N) { QualType VisitExpr(const Expr *S) { return S->IgnoreImplicitAsWritten()->getType(); } + QualType VisitMemberExpr(const MemberExpr *S) { + // The `foo` in `s.foo()` pretends not to have a real type! + if (S->getType()->isSpecificBuiltinType(BuiltinType::BoundMember)) + return Expr::findBoundMemberType(S); + return VisitExpr(S); + } // Exceptions for void expressions that operate on a type in some way. QualType VisitCXXDeleteExpr(const CXXDeleteExpr *S) { return S->getDestroyedType(); diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp index e9e6b6f79a2d..dba7f4f85b40 100644 --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -1829,8 +1829,9 @@ TEST(FindType, All) { struct $Target[[Target]] { operator int() const; }; struct Aggregate { Target a, b; }; Target t; + Target make(); - template class $smart_ptr[[smart_ptr]] { + template struct $smart_ptr[[smart_ptr]] { T& operator*(); T* operator->(); T* get(); @@ -1858,6 +1859,8 @@ TEST(FindType, All) { "void x() { ^if (t) {} }", "void x() { ^while (t) {} }", "void x() { ^do { } while (t); }", + "void x() { ^make(); }", + "void x(smart_ptr &t) { t.^get(); }", "^auto x = []() { return t; };", "Target* ^tptr = &t;", "Target ^tarray[3];",