mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-29 19:07:08 +00:00
Move IndexVar::def::declarations to IndexVar::declarations
This commit is contained in:
parent
e892c23955
commit
0bbabbcbd2
@ -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);
|
||||
|
@ -373,7 +373,6 @@ struct VarDefDefinitionData {
|
||||
ClangStorageClass storage = ClangStorageClass::SC_Invalid;
|
||||
optional<std::string> hover;
|
||||
optional<std::string> comments;
|
||||
std::vector<Range> declarations;
|
||||
// TODO: definitions should be a list of ranges, since there can be more
|
||||
// than one - when??
|
||||
optional<Range> definition_spelling;
|
||||
@ -397,7 +396,6 @@ struct VarDefDefinitionData {
|
||||
const VarDefDefinitionData<TypeId, FuncId, VarId, Range>& 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<Range> declarations;
|
||||
// Usages.
|
||||
std::vector<Range> uses;
|
||||
|
||||
|
17
src/query.cc
17
src/query.cc
@ -83,7 +83,6 @@ optional<QueryVar::Def> 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<QueryVar::Def> 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
|
||||
|
@ -256,10 +256,12 @@ struct QueryVar {
|
||||
using Def =
|
||||
VarDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryLocation>;
|
||||
using DefUpdate = WithUsr<Def>;
|
||||
using DeclarationsUpdate = MergeableUpdate<QueryVarId, QueryLocation>;
|
||||
using UsesUpdate = MergeableUpdate<QueryVarId, QueryLocation>;
|
||||
|
||||
Usr usr;
|
||||
optional<Def> def;
|
||||
std::vector<QueryLocation> declarations;
|
||||
std::vector<QueryLocation> uses;
|
||||
size_t detailed_name_idx = (size_t)-1;
|
||||
|
||||
@ -302,6 +304,7 @@ struct IndexUpdate {
|
||||
// Variable updates.
|
||||
std::vector<Usr> vars_removed;
|
||||
std::vector<QueryVar::DefUpdate> vars_def_update;
|
||||
std::vector<QueryVar::DeclarationsUpdate> vars_declarations;
|
||||
std::vector<QueryVar::UsesUpdate> 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
|
||||
|
@ -203,11 +203,11 @@ std::vector<QueryLocation> GetUsesOfSymbol(QueryDatabase* db,
|
||||
case SymbolKind::Var: {
|
||||
QueryVar& var = db->vars[symbol.idx];
|
||||
std::vector<QueryLocation> 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<QueryLocation> 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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user