[clangd] Print type for VarTemplateDecl in hover.

Print type for VarTemplateDecl in hover.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D115108
This commit is contained in:
lh123 2021-12-08 01:16:38 +08:00
parent 630c847b1b
commit 51dc466642
2 changed files with 31 additions and 0 deletions

View File

@ -594,6 +594,8 @@ HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP,
HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class"; HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D))
HI.Type = printType(TTP, PP); HI.Type = printType(TTP, PP);
else if (const auto *VT = dyn_cast<VarTemplateDecl>(D))
HI.Type = printType(VT->getTemplatedDecl()->getType(), PP);
// Fill in value with evaluated initializer if possible. // Fill in value with evaluated initializer if possible.
if (const auto *Var = dyn_cast<VarDecl>(D)) { if (const auto *Var = dyn_cast<VarDecl>(D)) {

View File

@ -901,6 +901,35 @@ class Foo {})cpp";
HI.Kind = index::SymbolKind::Unknown; HI.Kind = index::SymbolKind::Unknown;
HI.Type = "int[10]"; HI.Type = "int[10]";
HI.Value = "{1}"; HI.Value = "{1}";
}},
{// Var template decl
R"cpp(
using m_int = int;
template <int Size> 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 <int Size> m_int arr[Size]";
HI.TemplateParameters = {{{"int"}, {"Size"}, llvm::None}};
}},
{// Var template decl specialization
R"cpp(
using m_int = int;
template <int Size> 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) { for (const auto &Case : Cases) {
SCOPED_TRACE(Case.Code); SCOPED_TRACE(Case.Code);