sammccall created this revision. sammccall added a reviewer: kadircet. Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov. Herald added a project: clang.
This is part of https://github.com/clangd/clangd/issues/180. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D70209 Files: clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/unittests/XRefsTests.cpp Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -981,6 +981,16 @@ HI.NamespaceScope = ""; HI.Value = "3"; }}, + {R"cpp(enum Color { RED, [[GR^EEN]], };)cpp", + [](HoverInfo &HI) { + HI.Name = "GREEN"; + HI.NamespaceScope = ""; + HI.LocalScope = "Color::"; + HI.Definition = "GREEN"; + HI.Kind = SymbolKind::EnumMember; + HI.Type = "enum Color"; + HI.Value = "1"; + }}, // FIXME: We should use the Decl referenced, even if it comes from an // implicit instantiation. {R"cpp( Index: clang-tools-extra/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/clangd/XRefs.cpp +++ clang-tools-extra/clangd/XRefs.cpp @@ -657,6 +657,10 @@ Init->getType()); } } + } else if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) { + // Dependent enums (e.g. nested in template classes) don't have values yet. + if (!ECD->getType()->isDependentType()) + HI.Value = ECD->getInitVal().toString(10); } HI.Definition = printDefinition(D);
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -981,6 +981,16 @@ HI.NamespaceScope = ""; HI.Value = "3"; }}, + {R"cpp(enum Color { RED, [[GR^EEN]], };)cpp", + [](HoverInfo &HI) { + HI.Name = "GREEN"; + HI.NamespaceScope = ""; + HI.LocalScope = "Color::"; + HI.Definition = "GREEN"; + HI.Kind = SymbolKind::EnumMember; + HI.Type = "enum Color"; + HI.Value = "1"; + }}, // FIXME: We should use the Decl referenced, even if it comes from an // implicit instantiation. {R"cpp( Index: clang-tools-extra/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/clangd/XRefs.cpp +++ clang-tools-extra/clangd/XRefs.cpp @@ -657,6 +657,10 @@ Init->getType()); } } + } else if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) { + // Dependent enums (e.g. nested in template classes) don't have values yet. + if (!ECD->getType()->isDependentType()) + HI.Value = ECD->getInitVal().toString(10); } HI.Definition = printDefinition(D);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits