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 @@ -594,6 +594,8 @@ HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class"; else if (const auto *TTP = dyn_cast(D)) HI.Type = printType(TTP, PP); + else if (const auto *VT = dyn_cast(D)) + HI.Type = printType(VT->getTemplatedDecl()->getType(), PP); // Fill in value with evaluated initializer if possible. if (const auto *Var = dyn_cast(D)) { 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 @@ -901,6 +901,35 @@ HI.Kind = index::SymbolKind::Unknown; HI.Type = "int[10]"; HI.Value = "{1}"; + }}, + {// Var template decl + R"cpp( + using m_int = int; + + template m_int ^[[arr]][Size]; + )cpp", + [](HoverInfo &HI) { + HI.Name = "arr"; + HI.Kind = index::SymbolKind::Variable; + HI.Type = "m_int[Size]"; + HI.NamespaceScope = ""; + HI.Definition = "template m_int arr[Size]"; + HI.TemplateParameters = {{{"int"}, {"Size"}, llvm::None}}; + }}, + {// Var template decl specialization + R"cpp( + using m_int = int; + + template m_int arr[Size]; + + template <> m_int ^[[arr]]<4>[4]; + )cpp", + [](HoverInfo &HI) { + HI.Name = "arr<4>"; + HI.Kind = index::SymbolKind::Variable; + HI.Type = "m_int[4]"; + HI.NamespaceScope = ""; + HI.Definition = "m_int arr[4]"; }}}; for (const auto &Case : Cases) { SCOPED_TRACE(Case.Code);