[clangd] Fix SelectionTree behavior on implicit 'this'
llvm-svn: 370884
diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp
index 7717493..1877b1c 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -19,6 +19,7 @@
#include "clang/Lex/Lexer.h"
#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <string>
@@ -205,6 +206,11 @@
bool dataTraverseStmtPre(Stmt *X) {
if (!X)
return false;
+ // Implicit this in a MemberExpr is not filtered out by RecursiveASTVisitor.
+ // It would be nice if RAV handled this (!shouldTRaverseImplicitCode()).
+ if (auto *CTI = llvm::dyn_cast<CXXThisExpr>(X))
+ if (CTI->isImplicit())
+ return false;
auto N = DynTypedNode::create(*X);
if (canSafelySkipNode(N))
return false;