xndcn updated this revision to Diff 307622.
xndcn added a comment.

Update the diff with `getHoverContents(const NamedDecl ..)` overload function.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92041/new/

https://reviews.llvm.org/D92041

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


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,22 @@
             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 = "Foo";
+            HI.Kind = index::SymbolKind::Class;
+            HI.NamespaceScope = "ns::";
+            HI.Definition = "class Foo {}";
+          }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -630,7 +630,8 @@
 
 // Generates hover info for evaluatable expressions.
 // FIXME: Support hover for literals (esp user-defined)
-llvm::Optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST) {
+llvm::Optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST,
+                                           const SymbolIndex *Index) {
   // There's not much value in hovering over "42" and getting a hover card
   // saying "42 is an int", similar for other literals.
   if (isLiteral(E))
@@ -647,6 +648,10 @@
     HI.Value = *Val;
     HI.Name = std::string(getNameForExpr(E));
     return HI;
+  } else if (const CXXThisExpr *CTE = dyn_cast<CXXThisExpr>(E)) {
+    const NamedDecl *D = 
CTE->getType()->getPointeeType()->getAsCXXRecordDecl();
+    HI = getHoverContents(D, Index);
+    return HI;
   }
   return llvm::None;
 }
@@ -861,7 +866,7 @@
           HI->Value = printExprValue(N, AST.getASTContext());
         maybeAddCalleeArgInfo(N, *HI, AST.getASTContext().getPrintingPolicy());
       } else if (const Expr *E = N->ASTNode.get<Expr>()) {
-        HI = getHoverContents(E, AST);
+        HI = getHoverContents(E, AST, Index);
       }
       // FIXME: support hovers for other nodes?
       //  - built-in types


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,22 @@
             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 = "Foo";
+            HI.Kind = index::SymbolKind::Class;
+            HI.NamespaceScope = "ns::";
+            HI.Definition = "class Foo {}";
+          }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -630,7 +630,8 @@
 
 // Generates hover info for evaluatable expressions.
 // FIXME: Support hover for literals (esp user-defined)
-llvm::Optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST) {
+llvm::Optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST,
+                                           const SymbolIndex *Index) {
   // There's not much value in hovering over "42" and getting a hover card
   // saying "42 is an int", similar for other literals.
   if (isLiteral(E))
@@ -647,6 +648,10 @@
     HI.Value = *Val;
     HI.Name = std::string(getNameForExpr(E));
     return HI;
+  } else if (const CXXThisExpr *CTE = dyn_cast<CXXThisExpr>(E)) {
+    const NamedDecl *D = CTE->getType()->getPointeeType()->getAsCXXRecordDecl();
+    HI = getHoverContents(D, Index);
+    return HI;
   }
   return llvm::None;
 }
@@ -861,7 +866,7 @@
           HI->Value = printExprValue(N, AST.getASTContext());
         maybeAddCalleeArgInfo(N, *HI, AST.getASTContext().getPrintingPolicy());
       } else if (const Expr *E = N->ASTNode.get<Expr>()) {
-        HI = getHoverContents(E, AST);
+        HI = getHoverContents(E, AST, Index);
       }
       // FIXME: support hovers for other nodes?
       //  - built-in types
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to