From 54a38bcc7471d5cc0bb38366f04ed27fe2eca058 Mon Sep 17 00:00:00 2001 From: Ludovic Jozeau Date: Mon, 20 Jul 2020 15:02:19 +0200 Subject: [PATCH] remove pointer in DocumentSymbol.children and useless things --- src/messages/textDocument_document.cc | 41 +++++++++------------------ 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/src/messages/textDocument_document.cc b/src/messages/textDocument_document.cc index 166521ab..f2ba9f66 100644 --- a/src/messages/textDocument_document.cc +++ b/src/messages/textDocument_document.cc @@ -113,14 +113,10 @@ struct DocumentSymbol { SymbolKind kind; lsRange range; lsRange selectionRange; - std::vector> children; + std::vector children; }; -void reflect(JsonWriter &vis, std::unique_ptr &v); REFLECT_STRUCT(DocumentSymbol, name, detail, kind, range, selectionRange, children); -void reflect(JsonWriter &vis, std::unique_ptr &v) { - reflect(vis, *v); -} template bool ignore(const Def *def) { return false; } template <> bool ignore(const QueryType::Def *def) { @@ -129,16 +125,6 @@ template <> bool ignore(const QueryType::Def *def) { template <> bool ignore(const QueryVar::Def *def) { return !def || def->is_local(); } - -void uniquify(std::vector> &cs) { - std::sort(cs.begin(), cs.end(), - [](auto &l, auto &r) { return l->range < r->range; }); - cs.erase(std::unique(cs.begin(), cs.end(), - [](auto &l, auto &r) { return l->range == r->range; }), - cs.end()); - for (auto &c : cs) - uniquify(c->children); -} } // namespace void MessageHandler::textDocument_documentSymbol(JsonReader &reader, @@ -189,46 +175,45 @@ void MessageHandler::textDocument_documentSymbol(JsonReader &reader, std::push_heap(std::begin(syms), std::end(syms), sym_cmp); } - std::vector> result; + std::vector result; std::stack indent; while (!syms.empty()) { std::pop_heap(std::begin(syms), std::end(syms), sym_cmp); auto sym = syms.back(); syms.pop_back(); - std::unique_ptr ds = std::make_unique(); + DocumentSymbol ds; if (auto range = getLsRange(wf, sym.range)) { - ds->selectionRange = *range; - ds->range = ds->selectionRange; + ds.selectionRange = *range; + ds.range = ds.selectionRange; // For a macro expansion, M(name), we may use `M` for extent and // `name` for spell, do the check as selectionRange must be a subrange // of range. if (sym.extent.valid()) if (auto range1 = getLsRange(wf, sym.extent); range1 && range1->includes(*range)) - ds->range = *range1; + ds.range = *range1; } withEntity(db, sym, [&, sym = sym](const auto &entity) { auto const *def = entity.anyDef(); if (!def) return; - ds->name = def->name(false); - ds->detail = def->detailed_name; - ds->kind = def->kind; + ds.name = def->name(false); + ds.detail = def->detailed_name; + ds.kind = def->kind; - if (!ignore(def) && - (ds->kind == SymbolKind::Namespace || allows(sym))) { + if (!ignore(def) && (ds.kind == SymbolKind::Namespace || allows(sym))) { // drop symbols that are behind the current one - while (!indent.empty() && indent.top()->range.end < ds->range.start) { + while (!indent.empty() && indent.top()->range.end < ds.range.start) { indent.pop(); } - auto *cur_ds = ds.get(); if (indent.empty()) { result.push_back(std::move(ds)); + indent.push(&result.back()); } else { indent.top()->children.push_back(std::move(ds)); + indent.push(&indent.top()->children.back()); } - indent.push(cur_ds); } }); }