[clang-tools-extra] 283b6de - [clangd] Make go-to-type work on member function calls
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 25 19:18:53 PDT 2022
Author: Sam McCall
Date: 2022-09-26T04:18:43+02:00
New Revision: 283b6dec8d08520f73ebd4563966f491b49d47b2
URL: https://github.com/llvm/llvm-project/commit/283b6dec8d08520f73ebd4563966f491b49d47b2
DIFF: https://github.com/llvm/llvm-project/commit/283b6dec8d08520f73ebd4563966f491b49d47b2.diff
LOG: [clangd] Make go-to-type work on member function calls
Added:
Modified:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp
Removed:
################################################################################
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 @@ struct TargetFinder {
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 <typename T> class $smart_ptr[[smart_ptr]] {
+ template <typename T> 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<Target> &t) { t.^get(); }",
"^auto x = []() { return t; };",
"Target* ^tptr = &t;",
"Target ^tarray[3];",
More information about the cfe-commits
mailing list