Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -606,6 +606,17 @@ return HI; } +/// Generate a \p Hover object given the \p this pointer. +HoverInfo getHoverContents(const CXXThisExpr *CTE, const SymbolIndex *Index) { + const NamedDecl *D = CTE->getType()->getPointeeType()->getAsCXXRecordDecl(); + HoverInfo HI = getHoverContents(D, Index); + HI.Name = "this"; + // TODO: determine the symbol kind. + HI.Kind = index::SymbolKind::Unknown; + HI.Type = printType(CTE->getType(), D->getASTContext().getPrintingPolicy()); + return HI; +} + bool isLiteral(const Expr *E) { // Unfortunately there's no common base Literal classes inherits from // (apart from Expr), therefore these exclusions. @@ -860,6 +871,8 @@ if (!HI->Value) HI->Value = printExprValue(N, AST.getASTContext()); maybeAddCalleeArgInfo(N, *HI, AST.getASTContext().getPrintingPolicy()); + } else if (const CXXThisExpr *CTE = N->ASTNode.get()) { + HI = getHoverContents(CTE, Index); } else if (const Expr *E = N->ASTNode.get()) { HI = getHoverContents(E, AST); } Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -2019,6 +2019,23 @@ HI.NamespaceScope = ""; HI.Definition = "@interface MYObject\n@end"; }}, + { + R"cpp(// this expr + namespace ns { + class Foo { + Foo* bar() { + return [[t^his]]; + } + }; + }; + )cpp", + [](HoverInfo &HI) { + HI.Name = "this"; + HI.Type = "ns::Foo *"; + HI.Kind = index::SymbolKind::Unknown; + HI.NamespaceScope = "ns::"; + HI.Definition = "class Foo {}"; + }}, }; // Create a tiny index, so tests above can verify documentation is fetched.