diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp --- a/clang-tools-extra/clangd/Hover.cpp +++ b/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 { diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/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 + struct templ {}; + ^[[auto]] z = templ(); + )cpp", + [](HoverInfo &HI) { + HI.Name = "struct templ"; + HI.Kind = index::SymbolKind::Struct; + }}, }; // Create a tiny index, so tests above can verify documentation is fetched.