[PATCH] D115108: [clangd] Print type for VarTemplateDecl in hover.
liu hui via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 7 09:20:49 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG51dc466642c5: [clangd] Print type for VarTemplateDecl in hover. (authored by lh123).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115108/new/
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.392434.patch
Type: text/x-patch
Size: 1952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211207/20e950bd/attachment-0001.bin>
More information about the cfe-commits
mailing list