[clangd] Expose value of enumerators to Hover API. (not UI yet)

Summary: This is part of https://github.com/clangd/clangd/issues/180.

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70209
This commit is contained in:
Sam McCall 2019-11-13 22:24:17 +01:00
parent 058bc4c8d4
commit 37abeed814
2 changed files with 17 additions and 0 deletions

View File

@ -657,6 +657,10 @@ static HoverInfo getHoverContents(const Decl *D, const SymbolIndex *Index) {
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);

View File

@ -981,6 +981,19 @@ void foo())cpp";
HI.NamespaceScope = "";
HI.Value = "3";
}},
{R"cpp(
enum Color { RED, GREEN, };
Color x = [[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(