[PATCH] D115108: [clangd] Print type for VarTemplateDecl in hover.
liu hui via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 4 20:09:54 PST 2021
lh123 created this revision.
lh123 added reviewers: kadircet, sammccall.
lh123 added a project: clang-tools-extra.
Herald added subscribers: usaxena95, arphaman.
lh123 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Print type for `VarTemplateDecl` in hover.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115108
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
@@ -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 <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) {
SCOPED_TRACE(Case.Code);
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -594,6 +594,8 @@
HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
else if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D))
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.
if (const auto *Var = dyn_cast<VarDecl>(D)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115108.391886.patch
Type: text/x-patch
Size: 1952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211205/5da43054/attachment.bin>
More information about the cfe-commits
mailing list