From 03df4085fb721e8c5e44e93abb168633241bac89 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 22 Feb 2019 23:49:37 +0800 Subject: [PATCH] Make hover more detailed (e.g. include inheritance info) --- src/indexer.cc | 4 +++- src/messages/textDocument_hover.cc | 38 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index 894286f3..b6653fc3 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -815,10 +815,12 @@ public: do_def_decl(type); if (Spell != Loc) 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) type->def.detailed_name = Intern(info->short_name); else + // OrigD may be detailed, e.g. "struct D : B {}" SetName(OrigD, info->short_name, info->qualified, type->def); } if (is_def || is_decl) { diff --git a/src/messages/textDocument_hover.cc b/src/messages/textDocument_hover.cc index 50cbf620..60c00fb9 100644 --- a/src/messages/textDocument_hover.cc +++ b/src/messages/textDocument_hover.cc @@ -47,33 +47,33 @@ GetHover(DB *db, LanguageId lang, SymbolRef sym, int file_id) { const char *comments = nullptr; std::optional ls_comments, hover; WithEntity(db, sym, [&](const auto &entity) { - std::remove_reference_t *def = nullptr; for (auto &d : entity.def) { if (d.spell) { 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) break; } } - if (!def && entity.def.size()) { - def = &entity.def[0]; - if (def->comments[0]) - comments = def->comments; - } - if (def) { - MarkedString m; - m.language = LanguageIdentifier(lang); - if (def->hover[0]) { - m.value = def->hover; - hover = m; - } else if (def->detailed_name[0]) { - m.value = def->detailed_name; - hover = m; - } - if (comments) - ls_comments = MarkedString{std::nullopt, comments}; + if (!hover && entity.def.size()) { + auto &d = entity.def[0]; + if (d.comments[0]) + comments = d.comments; + hover = {LanguageIdentifier(lang)}; + if (d.hover[0]) + hover->value = d.hover; + else if (d.detailed_name[0]) + hover->value = d.detailed_name; } + if (comments) + ls_comments = MarkedString{std::nullopt, comments}; }); return {hover, ls_comments}; }