Skip to content

Commit 51dc466

Browse files
committed
[clangd] Print type for VarTemplateDecl in hover.
Print type for VarTemplateDecl in hover. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D115108
1 parent 630c847 commit 51dc466

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

clang-tools-extra/clangd/Hover.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP,
594594
HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
595595
else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D))
596596
HI.Type = printType(TTP, PP);
597+
else if (const auto *VT = dyn_cast<VarTemplateDecl>(D))
598+
HI.Type = printType(VT->getTemplatedDecl()->getType(), PP);
597599

598600
// Fill in value with evaluated initializer if possible.
599601
if (const auto *Var = dyn_cast<VarDecl>(D)) {

clang-tools-extra/clangd/unittests/HoverTests.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,35 @@ class Foo {})cpp";
901901
HI.Kind = index::SymbolKind::Unknown;
902902
HI.Type = "int[10]";
903903
HI.Value = "{1}";
904+
}},
905+
{// Var template decl
906+
R"cpp(
907+
using m_int = int;
908+
909+
template <int Size> m_int ^[[arr]][Size];
910+
)cpp",
911+
[](HoverInfo &HI) {
912+
HI.Name = "arr";
913+
HI.Kind = index::SymbolKind::Variable;
914+
HI.Type = "m_int[Size]";
915+
HI.NamespaceScope = "";
916+
HI.Definition = "template <int Size> m_int arr[Size]";
917+
HI.TemplateParameters = {{{"int"}, {"Size"}, llvm::None}};
918+
}},
919+
{// Var template decl specialization
920+
R"cpp(
921+
using m_int = int;
922+
923+
template <int Size> m_int arr[Size];
924+
925+
template <> m_int ^[[arr]]<4>[4];
926+
)cpp",
927+
[](HoverInfo &HI) {
928+
HI.Name = "arr<4>";
929+
HI.Kind = index::SymbolKind::Variable;
930+
HI.Type = "m_int[4]";
931+
HI.NamespaceScope = "";
932+
HI.Definition = "m_int arr[4]";
904933
}}};
905934
for (const auto &Case : Cases) {
906935
SCOPED_TRACE(Case.Code);

0 commit comments

Comments
 (0)