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)) {
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)) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits