Author: lh123 Date: 2021-12-08T01:20:14+08:00 New Revision: 51dc466642c5566c289468b269a8c69b0e447720
URL: https://github.com/llvm/llvm-project/commit/51dc466642c5566c289468b269a8c69b0e447720 DIFF: https://github.com/llvm/llvm-project/commit/51dc466642c5566c289468b269a8c69b0e447720.diff LOG: [clangd] Print type for VarTemplateDecl in hover. Print type for VarTemplateDecl in hover. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D115108 Added: Modified: clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index 76e9f4d243b9..16a7d5832581 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -594,6 +594,8 @@ HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP, 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)) { diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 0d71dcbf8a93..5376750b25b4 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -901,6 +901,35 @@ class Foo {})cpp"; 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); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits