Make hover more detailed (e.g. include inheritance info)

This commit is contained in:
Fangrui Song 2019-02-22 23:49:37 +08:00
parent f35883f9b4
commit 9dea14e783
2 changed files with 22 additions and 20 deletions

View File

@ -815,10 +815,12 @@ public:
do_def_decl(type); do_def_decl(type);
if (Spell != Loc) if (Spell != Loc)
AddMacroUse(db, SM, usr, Kind::Type, Spell); AddMacroUse(db, SM, usr, Kind::Type, Spell);
if (type->def.detailed_name[0] == '\0' && info->short_name.size()) { if ((is_def || type->def.detailed_name[0] == '\0') &&
info->short_name.size()) {
if (D->getKind() == Decl::TemplateTypeParm) if (D->getKind() == Decl::TemplateTypeParm)
type->def.detailed_name = Intern(info->short_name); type->def.detailed_name = Intern(info->short_name);
else else
// OrigD may be detailed, e.g. "struct D : B {}"
SetName(OrigD, info->short_name, info->qualified, type->def); SetName(OrigD, info->short_name, info->qualified, type->def);
} }
if (is_def || is_decl) { if (is_def || is_decl) {

View File

@ -47,33 +47,33 @@ GetHover(DB *db, LanguageId lang, SymbolRef sym, int file_id) {
const char *comments = nullptr; const char *comments = nullptr;
std::optional<MarkedString> ls_comments, hover; std::optional<MarkedString> ls_comments, hover;
WithEntity(db, sym, [&](const auto &entity) { WithEntity(db, sym, [&](const auto &entity) {
std::remove_reference_t<decltype(entity.def[0])> *def = nullptr;
for (auto &d : entity.def) { for (auto &d : entity.def) {
if (d.spell) { if (d.spell) {
comments = d.comments[0] ? d.comments : nullptr; comments = d.comments[0] ? d.comments : nullptr;
def = &d; if (const char *s =
d.hover[0] ? d.hover
: d.detailed_name[0] ? d.detailed_name : nullptr) {
if (!hover)
hover = {LanguageIdentifier(lang), s};
else if (strlen(s) > hover->value.size())
hover->value = s;
}
if (d.spell->file_id == file_id) if (d.spell->file_id == file_id)
break; break;
} }
} }
if (!def && entity.def.size()) { if (!hover && entity.def.size()) {
def = &entity.def[0]; auto &d = entity.def[0];
if (def->comments[0]) if (d.comments[0])
comments = def->comments; comments = d.comments;
} hover = {LanguageIdentifier(lang)};
if (def) { if (d.hover[0])
MarkedString m; hover->value = d.hover;
m.language = LanguageIdentifier(lang); else if (d.detailed_name[0])
if (def->hover[0]) { hover->value = d.detailed_name;
m.value = def->hover;
hover = m;
} else if (def->detailed_name[0]) {
m.value = def->detailed_name;
hover = m;
} }
if (comments) if (comments)
ls_comments = MarkedString{std::nullopt, comments}; ls_comments = MarkedString{std::nullopt, comments};
}
}); });
return {hover, ls_comments}; return {hover, ls_comments};
} }