From e785d3f47755f4718b6790c2d7abfae068e1ffc1 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 21 Feb 2018 22:34:34 -0800 Subject: [PATCH] Keep a list of QueryType --- src/indexer.h | 4 --- src/message_handler.cc | 40 ++++++++++++--------- src/messages/text_document_references.cc | 2 ++ src/query.cc | 7 +--- src/query.h | 46 ++++++++++-------------- 5 files changed, 46 insertions(+), 53 deletions(-) diff --git a/src/indexer.h b/src/indexer.h index a0fc4ed9..f79588f6 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -124,10 +124,6 @@ struct SymbolRef : Reference { SymbolRef() = default; SymbolRef(Range range, Id id, SymbolKind kind, Role role) : Reference{range, id, kind, role} {} - SymbolRef(Reference ref) : Reference(ref) {} - // FIXME Remove - SymbolRef(SymbolIdx si) - : Reference{Range(), si.id, si.kind, Role::None} {} }; // Represents an occurrence of a variable/type, |id,kind| refer to the lexical diff --git a/src/message_handler.cc b/src/message_handler.cc index b4f2aaa5..c14228c3 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -117,7 +117,12 @@ void EmitSemanticHighlighting(QueryDatabase* db, // This switch statement also filters out symbols that are not highlighted. switch (sym.kind) { case SymbolKind::Func: { - const QueryFunc::Def* def = db->GetFunc(sym).AnyDef(); + const QueryFunc::Def* def = nullptr; + for (auto& i : db->GetFunc(sym).def) { + def = &i; + if (i.spell) + break; + } if (!def) continue; // applies to for loop // Don't highlight overloadable operators or implicit lambda -> @@ -129,6 +134,7 @@ void EmitSemanticHighlighting(QueryDatabase* db, if (def->spell) parent_kind = def->spell->kind; kind = def->kind; + storage = def->storage; detailed_name = short_name; // Check whether the function name is actually there. @@ -149,25 +155,27 @@ void EmitSemanticHighlighting(QueryDatabase* db, } break; } - case SymbolKind::Var: { - if (const QueryVar::Def* def = db->GetVar(sym).AnyDef()) { - if (def->spell) - parent_kind = def->spell->kind; - kind = def->kind; - storage = def->storage; - detailed_name = def->ShortName(); + case SymbolKind::Type: + for (auto& def : db->GetType(sym).def) { + kind = def.kind; + detailed_name = def.detailed_name; + if (def.spell) { + parent_kind = def.spell->kind; + break; + } } break; - } - case SymbolKind::Type: { - if (const QueryType::Def* def = db->GetType(sym).AnyDef()) { - if (def->spell) - parent_kind = def->spell->kind; - kind = def->kind; - detailed_name = def->detailed_name; + case SymbolKind::Var: + for (auto& def : db->GetVar(sym).def) { + kind = def.kind; + storage = def.storage; + detailed_name = def.detailed_name; + if (def.spell) { + parent_kind = def.spell->kind; + break; + } } break; - } default: continue; // applies to for loop } diff --git a/src/messages/text_document_references.cc b/src/messages/text_document_references.cc index af693d39..0d3e01ee 100644 --- a/src/messages/text_document_references.cc +++ b/src/messages/text_document_references.cc @@ -82,6 +82,8 @@ struct TextDocumentReferencesHandler break; } + if ((int)out.result.size() >= config->xref.maxNum) + out.result.resize(config->xref.maxNum); QueueManager::WriteStdout(IpcId::TextDocumentReferences, out); } }; diff --git a/src/query.cc b/src/query.cc index 42753ce9..3f2f59d8 100644 --- a/src/query.cc +++ b/src/query.cc @@ -879,12 +879,7 @@ void QueryDatabase::ImportOrUpdate( assert(it->second.id >= 0 && it->second.id < types.size()); QueryType& existing = types[it->second.id]; - // TODO Investigate why a list of Def makes finding-definition fail. - //if (!TryReplaceDef(existing.def, std::move(def.value))) { - // - // Keep the existing definition if it is higher quality. - if (!(existing.AnyDef() && existing.AnyDef()->spell && - !def.value.spell)) { + if (!TryReplaceDef(existing.def, std::move(def.value))) { existing.def.push_front(std::move(def.value)); UpdateSymbols(&existing.symbol_idx, SymbolKind::Type, it->second); } diff --git a/src/query.h b/src/query.h index 5d72e92d..0faca564 100644 --- a/src/query.h +++ b/src/query.h @@ -133,7 +133,23 @@ MAKE_REFLECT_STRUCT(QueryFile::Def, inactive_regions, dependencies); -struct QueryType { +template +struct QueryEntity { + Def* AnyDef() { + Def* ret = nullptr; + for (auto& i : static_cast(this)->def) { + ret = &i; + if (i.spell) + break; + } + return ret; + } + const Def* AnyDef() const { + return const_cast(this)->AnyDef(); + } +}; + +struct QueryType : QueryEntity> { using Def = TypeDefDefinitionData; using DefUpdate = WithUsr; using DeclarationsUpdate = MergeableUpdate; @@ -150,17 +166,9 @@ struct QueryType { std::vector uses; explicit QueryType(const Usr& usr) : usr(usr) {} - const Def* AnyDef() const { - if (def.empty()) return nullptr; - return &def.front(); - } - Def* AnyDef() { - if (def.empty()) return nullptr; - return &def.front(); - } }; -struct QueryFunc { +struct QueryFunc : QueryEntity> { using Def = FuncDefDefinitionData; using DefUpdate = WithUsr; using DeclarationsUpdate = MergeableUpdate; @@ -175,17 +183,9 @@ struct QueryFunc { std::vector uses; explicit QueryFunc(const Usr& usr) : usr(usr) {} - const Def* AnyDef() const { - if (def.empty()) return nullptr; - return &def.front(); - } - Def* AnyDef() { - if (def.empty()) return nullptr; - return &def.front(); - } }; -struct QueryVar { +struct QueryVar : QueryEntity> { using Def = VarDefDefinitionData; using DefUpdate = WithUsr; using DeclarationsUpdate = MergeableUpdate; @@ -198,14 +198,6 @@ struct QueryVar { std::vector uses; explicit QueryVar(const Usr& usr) : usr(usr) {} - const Def* AnyDef() const { - if (def.empty()) return nullptr; - return &def.front(); - } - Def* AnyDef() { - if (def.empty()) return nullptr; - return &def.front(); - } }; struct IndexUpdate {