diff --git a/src/indexer.cc b/src/indexer.cc index fb842148..e735ff6e 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1431,7 +1431,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { var->def.definition_spelling = decl_spell; var->def.definition_extent = decl_cursor.get_extent(); } else { - var->def.declarations.push_back(decl_spell); + var->declarations.push_back(decl_spell); } AddDeclInitializerUsages(db, decl_cursor); diff --git a/src/indexer.h b/src/indexer.h index 4fa78593..ab3f8581 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -373,7 +373,6 @@ struct VarDefDefinitionData { ClangStorageClass storage = ClangStorageClass::SC_Invalid; optional hover; optional comments; - std::vector declarations; // TODO: definitions should be a list of ranges, since there can be more // than one - when?? optional definition_spelling; @@ -397,7 +396,6 @@ struct VarDefDefinitionData { const VarDefDefinitionData& other) const { return short_name == other.short_name && detailed_name == other.detailed_name && hover == other.hover && - declarations.size() == other.declarations.size() && definition_spelling == other.definition_spelling && definition_extent == other.definition_extent && variable_type == other.variable_type && @@ -439,6 +437,7 @@ struct IndexVar { Def def; + std::vector declarations; // Usages. std::vector uses; diff --git a/src/query.cc b/src/query.cc index 2bee6508..659bb4b6 100644 --- a/src/query.cc +++ b/src/query.cc @@ -83,7 +83,6 @@ optional ToQuery(const IdMap& id_map, const IndexVar::Def& var) { result.storage = var.storage; result.hover = var.hover; result.comments = var.comments; - result.declarations = id_map.ToQuery(var.declarations); result.definition_spelling = id_map.ToQuery(var.definition_spelling); result.definition_extent = id_map.ToQuery(var.definition_extent); result.variable_type = id_map.ToQuery(var.variable_type); @@ -264,6 +263,10 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) { var.def.definition_spelling.value()); if (var.def.definition_extent.has_value()) add_outline(id_map.ToSymbol(var.id), var.def.definition_extent.value()); + for (const Range& decl : var.declarations) { + add_all_symbols(id_map.ToSymbol(var.id), decl); + add_outline(id_map.ToSymbol(var.id), decl); + } for (const Range& use : var.uses) add_all_symbols(id_map.ToSymbol(var.id), use); } @@ -658,6 +661,10 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, if (var->def.definition_spelling) { vars_removed.push_back(var->usr); } else { + if (!var->declarations.empty()) + vars_declarations.push_back(QueryVar::DeclarationsUpdate( + previous_id_map.ToQuery(var->id), {}, + previous_id_map.ToQuery(var->declarations))); if (!var->uses.empty()) vars_uses.push_back( QueryVar::UsesUpdate(previous_id_map.ToQuery(var->id), {}, @@ -669,6 +676,10 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, optional def_update = ToQuery(current_id_map, var->def); if (def_update) vars_def_update.push_back(QueryVar::DefUpdate(var->usr, *def_update)); + if (!var->declarations.empty()) + vars_declarations.push_back(QueryVar::DeclarationsUpdate( + current_id_map.ToQuery(var->id), + current_id_map.ToQuery(var->declarations))); if (!var->uses.empty()) vars_uses.push_back( QueryVar::UsesUpdate(current_id_map.ToQuery(var->id), @@ -687,6 +698,8 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, vars_def_update.push_back( QueryVar::DefUpdate(current->usr, *current_remapped_def)); + PROCESS_UPDATE_DIFF(QueryVarId, vars_declarations, declarations, + QueryLocation); PROCESS_UPDATE_DIFF(QueryVarId, vars_uses, uses, QueryLocation); }); @@ -715,6 +728,7 @@ void IndexUpdate::Merge(const IndexUpdate& update) { INDEX_UPDATE_APPEND(vars_removed); INDEX_UPDATE_APPEND(vars_def_update); + INDEX_UPDATE_MERGE(vars_declarations); INDEX_UPDATE_MERGE(vars_uses); #undef INDEX_UPDATE_APPEND @@ -805,6 +819,7 @@ void QueryDatabase::ApplyIndexUpdate(IndexUpdate* update) { RemoveUsrs(SymbolKind::Var, update->vars_removed); ImportOrUpdate(update->vars_def_update); + HANDLE_MERGEABLE(vars_declarations, declarations, vars); HANDLE_MERGEABLE(vars_uses, uses, vars); #undef HANDLE_MERGEABLE diff --git a/src/query.h b/src/query.h index 63547c0d..38d4ce6b 100644 --- a/src/query.h +++ b/src/query.h @@ -256,10 +256,12 @@ struct QueryVar { using Def = VarDefDefinitionData; using DefUpdate = WithUsr; + using DeclarationsUpdate = MergeableUpdate; using UsesUpdate = MergeableUpdate; Usr usr; optional def; + std::vector declarations; std::vector uses; size_t detailed_name_idx = (size_t)-1; @@ -302,6 +304,7 @@ struct IndexUpdate { // Variable updates. std::vector vars_removed; std::vector vars_def_update; + std::vector vars_declarations; std::vector vars_uses; private: @@ -328,6 +331,7 @@ MAKE_REFLECT_STRUCT(IndexUpdate, funcs_callers, vars_removed, vars_def_update, + vars_declarations, vars_uses); // The query database is heavily optimized for fast queries. It is stored diff --git a/src/query_utils.cc b/src/query_utils.cc index 8d848230..6f5b07dc 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -203,11 +203,11 @@ std::vector GetUsesOfSymbol(QueryDatabase* db, case SymbolKind::Var: { QueryVar& var = db->vars[symbol.idx]; std::vector ret = var.uses; - if (include_decl && var.def) { - if (var.def->definition_spelling) + if (include_decl) { + if (var.def && var.def->definition_spelling) ret.push_back(*var.def->definition_spelling); - ret.insert(ret.end(), var.def->declarations.begin(), - var.def->declarations.end()); + ret.insert(ret.end(), var.declarations.begin(), + var.declarations.end()); } return ret; } @@ -242,10 +242,7 @@ std::vector GetDeclarationsOfSymbolForGotoDefinition( return func.declarations; } case SymbolKind::Var: { - QueryVar& var = db->vars[symbol.idx]; - if (var.def) - return var.def->declarations; - break; + return db->vars[symbol.idx].declarations; } default: break; diff --git a/src/serializer.cc b/src/serializer.cc index 47c52971..1c60f40a 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -189,7 +189,7 @@ void Reflect(TVisitor& visitor, IndexVar& value) { REFLECT_MEMBER2("storage", value.def.storage); REFLECT_MEMBER2("hover", value.def.hover); REFLECT_MEMBER2("comments", value.def.comments); - REFLECT_MEMBER2("declarations", value.def.declarations); + REFLECT_MEMBER2("declarations", value.declarations); REFLECT_MEMBER2("definition_spelling", value.def.definition_spelling); REFLECT_MEMBER2("definition_extent", value.def.definition_extent); REFLECT_MEMBER2("variable_type", value.def.variable_type);