[PATCH] D71597: [clangd][NFC] Make use of TagDecl inside type for hover on auto

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 17 07:38:43 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rG3d15605358eb: [clangd][NFC] Make use of TagDecl inside type for hover on auto (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71597

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
@@ -1396,6 +1396,32 @@
             HI.Definition = "struct Test &&test = {}";
             HI.Value = "{}";
           }},
+      {
+          R"cpp(// auto on alias
+          typedef int int_type;
+          ^[[auto]] x = int_type();
+          )cpp",
+          [](HoverInfo &HI) { HI.Name = "int"; }},
+      {
+          R"cpp(// auto on alias
+          struct cls {};
+          typedef cls cls_type;
+          ^[[auto]] y = cls_type();
+          )cpp",
+          [](HoverInfo &HI) {
+            HI.Name = "struct cls";
+            HI.Kind = index::SymbolKind::Struct;
+          }},
+      {
+          R"cpp(// auto on alias
+          template <class>
+          struct templ {};
+          ^[[auto]] z = templ<int>();
+          )cpp",
+          [](HoverInfo &HI) {
+            HI.Name = "struct templ<int>";
+            HI.Kind = index::SymbolKind::Struct;
+          }},
   };
 
   // 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
@@ -342,15 +342,15 @@
 }
 
 /// Generate a \p Hover object given the type \p T.
-HoverInfo getHoverContents(QualType T, const Decl *D, ASTContext &ASTCtx,
-                                  const SymbolIndex *Index) {
+HoverInfo getHoverContents(QualType T, ASTContext &ASTCtx,
+                           const SymbolIndex *Index) {
   HoverInfo HI;
   llvm::raw_string_ostream OS(HI.Name);
   PrintingPolicy Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy());
   T.print(OS, Policy);
   OS.flush();
 
-  if (D) {
+  if (const auto *D = T->getAsTagDecl()) {
     HI.Kind = index::getSymbolInfo(D).Kind;
     enhanceFromIndex(HI, D, Index);
   }
@@ -396,12 +396,7 @@
       getBeginningOfIdentifier(Pos, SM, AST.getLangOpts()));
 
   if (auto Deduced = getDeducedType(AST.getASTContext(), SourceLocationBeg)) {
-    // Find the corresponding decl to populate kind and fetch documentation.
-    DeclRelationSet Rel = DeclRelation::TemplatePattern | DeclRelation::Alias;
-    auto Decls =
-        targetDecl(ast_type_traits::DynTypedNode::create(*Deduced), Rel);
-    HI = getHoverContents(*Deduced, Decls.empty() ? nullptr : Decls.front(),
-                          AST.getASTContext(), Index);
+    HI = getHoverContents(*Deduced, AST.getASTContext(), Index);
   } else if (auto M = locateMacroAt(SourceLocationBeg, AST.getPreprocessor())) {
     HI = getHoverContents(*M, AST);
   } else {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71597.234300.patch
Type: text/x-patch
Size: 2803 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191217/79f4dccd/attachment-0001.bin>


More information about the cfe-commits mailing list