mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 09:50:26 +00:00
Migrate QueryableFuncDef to indices
This commit is contained in:
parent
64d65584fd
commit
fffb3d3fcc
@ -478,6 +478,22 @@ void AddCodeLens(
|
||||
AddCodeLens(db, result, loc, uses0, exclude_loc, only_interesting, singular, plural);
|
||||
}
|
||||
|
||||
void AddCodeLens(
|
||||
QueryableDatabase* db,
|
||||
std::vector<TCodeLens>* result,
|
||||
QueryableLocation loc,
|
||||
const std::vector<QueryFuncRef>& uses,
|
||||
bool exclude_loc,
|
||||
bool only_interesting,
|
||||
const char* singular,
|
||||
const char* plural) {
|
||||
std::vector<QueryableLocation> uses0;
|
||||
uses0.reserve(uses.size());
|
||||
for (const QueryFuncRef& use : uses)
|
||||
uses0.push_back(use.loc);
|
||||
AddCodeLens(db, result, loc, uses0, exclude_loc, only_interesting, singular, plural);
|
||||
}
|
||||
|
||||
void AddCodeLens(
|
||||
QueryableDatabase* db,
|
||||
std::vector<TCodeLens>* result,
|
||||
@ -516,6 +532,25 @@ void AddCodeLens(
|
||||
AddCodeLens(db, result, loc, uses0, exclude_loc, only_interesting, singular, plural);
|
||||
}
|
||||
|
||||
void AddCodeLens(
|
||||
QueryableDatabase* db,
|
||||
std::vector<TCodeLens>* result,
|
||||
QueryableLocation loc,
|
||||
const std::vector<QueryFuncId>& usrs,
|
||||
bool exclude_loc,
|
||||
bool only_interesting,
|
||||
const char* singular,
|
||||
const char* plural) {
|
||||
std::vector<QueryableLocation> uses0;
|
||||
uses0.reserve(usrs.size());
|
||||
for (const QueryFuncId& usr : usrs) {
|
||||
optional<QueryableLocation> loc = GetDefinitionSpellingOfSymbol(db, usr);
|
||||
if (loc)
|
||||
uses0.push_back(loc.value());
|
||||
}
|
||||
AddCodeLens(db, result, loc, uses0, exclude_loc, only_interesting, singular, plural);
|
||||
}
|
||||
|
||||
void AddCodeLens(
|
||||
QueryableDatabase* db,
|
||||
std::vector<TCodeLens>* result,
|
||||
@ -705,10 +740,7 @@ void QueryDbMainLoop(
|
||||
info.name = def.def.qualified_name;
|
||||
if (def.def.declaring_type.has_value()) {
|
||||
info.kind = lsSymbolKind::Method;
|
||||
Usr declaring = def.def.declaring_type.value();
|
||||
info.containerName =
|
||||
db->types[db->usr_to_symbol[declaring].idx]
|
||||
.def.qualified_name;
|
||||
info.containerName = db->types[def.def.declaring_type->id].def.qualified_name;
|
||||
}
|
||||
else {
|
||||
info.kind = lsSymbolKind::Function;
|
||||
@ -852,10 +884,7 @@ void QueryDbMainLoop(
|
||||
info.name = def.def.qualified_name;
|
||||
if (def.def.declaring_type.has_value()) {
|
||||
info.kind = lsSymbolKind::Method;
|
||||
Usr declaring = def.def.declaring_type.value();
|
||||
info.containerName =
|
||||
db->types[db->usr_to_symbol[declaring].idx]
|
||||
.def.qualified_name;
|
||||
info.containerName = db->types[def.def.declaring_type->id].def.qualified_name;
|
||||
}
|
||||
else {
|
||||
info.kind = lsSymbolKind::Function;
|
||||
|
@ -1140,8 +1140,8 @@ void indexEntityReference(CXClientData client_data,
|
||||
IndexedFuncDef* caller_def = db->Resolve(caller_id);
|
||||
IndexedFuncDef* called_def = db->Resolve(called_id);
|
||||
|
||||
caller_def->def.callees.push_back(FuncRef(called_id, loc_spelling.value()));
|
||||
called_def->callers.push_back(FuncRef(caller_id, loc_spelling.value()));
|
||||
caller_def->def.callees.push_back(IndexFuncRef(called_id, loc_spelling.value()));
|
||||
called_def->callers.push_back(IndexFuncRef(caller_id, loc_spelling.value()));
|
||||
AddUsage(called_def->uses, loc_spelling.value());
|
||||
} else {
|
||||
IndexedFuncDef* called_def = db->Resolve(called_id);
|
||||
|
@ -83,9 +83,9 @@ bool operator!=(const Ref<T>& a, const Ref<T>& b) {
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
using TypeRef = Ref<IndexedTypeDef>;
|
||||
using FuncRef = Ref<IndexedFuncDef>;
|
||||
using VarRef = Ref<IndexedVarDef>;
|
||||
using IndexTypeRef = Ref<IndexedTypeDef>;
|
||||
using IndexFuncRef = Ref<IndexedFuncDef>;
|
||||
using IndexVarRef = Ref<IndexedVarDef>;
|
||||
|
||||
// TODO: skip as much forward-processing as possible when |is_system_def| is
|
||||
// set to false.
|
||||
@ -272,7 +272,7 @@ void Reflect(
|
||||
}
|
||||
|
||||
struct IndexedFuncDef {
|
||||
using Def = FuncDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, FuncRef, Range>;
|
||||
using Def = FuncDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, IndexFuncRef, Range>;
|
||||
Def def;
|
||||
|
||||
IndexFuncId id;
|
||||
@ -289,7 +289,7 @@ struct IndexedFuncDef {
|
||||
// or in class initializer list (redirect to class ctor?)
|
||||
// - Right now those usages will not get listed here (but they should be
|
||||
// inside of all_uses).
|
||||
std::vector<FuncRef> callers;
|
||||
std::vector<IndexFuncRef> callers;
|
||||
|
||||
// All usages. For interesting usages, see callees.
|
||||
std::vector<Range> uses;
|
||||
|
45
src/query.cc
45
src/query.cc
@ -34,7 +34,7 @@ QueryableLocation MapIdToUsr(const IdMap& id_map, const Range& range) {
|
||||
return QueryableLocation(id_map.primary_file, range);
|
||||
}
|
||||
// TODO: remove
|
||||
UsrRef MapIdToUsr(const IdMap& id_map, const FuncRef& id) {
|
||||
UsrRef MapIdToUsr(const IdMap& id_map, const IndexFuncRef& id) {
|
||||
assert(id_map.local_ids.func_id_to_usr.find(id.id) != id_map.local_ids.func_id_to_usr.end());
|
||||
return UsrRef(
|
||||
id_map.local_ids.func_id_to_usr.find(id.id)->second /*usr*/,
|
||||
@ -65,8 +65,8 @@ std::vector<Usr> MapIdToUsr(const IdMap& id_map, const std::vector<IndexVarId>&
|
||||
return Transform<IndexVarId, Usr>(id_map, ids);
|
||||
}
|
||||
// TODO: remove
|
||||
std::vector<UsrRef> MapIdToUsr(const IdMap& id_map, const std::vector<FuncRef>& ids) {
|
||||
return Transform<FuncRef, UsrRef>(id_map, ids);
|
||||
std::vector<UsrRef> MapIdToUsr(const IdMap& id_map, const std::vector<IndexFuncRef>& ids) {
|
||||
return Transform<IndexFuncRef, UsrRef>(id_map, ids);
|
||||
}
|
||||
std::vector<QueryableLocation> MapIdToUsr(const IdMap& id_map, const std::vector<Range>& ids) {
|
||||
return Transform<Range, QueryableLocation>(id_map, ids);
|
||||
@ -91,16 +91,12 @@ QueryableFuncDef::DefUpdate MapIdToUsr(const IdMap& id_map, const IndexedFuncDef
|
||||
QueryableFuncDef::DefUpdate result(def.usr);
|
||||
result.short_name = def.short_name;
|
||||
result.qualified_name = def.qualified_name;
|
||||
if (def.definition_spelling)
|
||||
result.definition_spelling = MapIdToUsr(id_map, def.definition_spelling.value());
|
||||
if (def.definition_extent)
|
||||
result.definition_extent = MapIdToUsr(id_map, def.definition_extent.value());
|
||||
if (def.declaring_type)
|
||||
result.declaring_type = MapIdToUsr(id_map, def.declaring_type.value());
|
||||
if (def.base)
|
||||
result.base = MapIdToUsr(id_map, def.base.value());
|
||||
result.locals = MapIdToUsr(id_map, def.locals);
|
||||
result.callees = MapIdToUsr(id_map, def.callees);
|
||||
result.definition_spelling = id_map.ToQuery(def.definition_spelling);
|
||||
result.definition_extent = id_map.ToQuery(def.definition_extent);
|
||||
result.declaring_type = id_map.ToQuery(def.declaring_type);
|
||||
result.base = id_map.ToQuery(def.base);
|
||||
result.locals = id_map.ToQuery(def.locals);
|
||||
result.callees = id_map.ToQuery(def.callees);
|
||||
return result;
|
||||
}
|
||||
QueryableVarDef::DefUpdate MapIdToUsr(const IdMap& id_map, const IndexedVarDef::Def& def) {
|
||||
@ -195,8 +191,8 @@ QueryableTypeDef::QueryableTypeDef(const IdMap& id_map, const IndexedTypeDef& in
|
||||
QueryableFuncDef::QueryableFuncDef(const IdMap& id_map, const IndexedFuncDef& indexed)
|
||||
: def(MapIdToUsr(id_map, indexed.def)) {
|
||||
declarations = MapIdToUsr(id_map, indexed.declarations);
|
||||
derived = MapIdToUsr(id_map, indexed.derived);
|
||||
callers = MapIdToUsr(id_map, indexed.callers);
|
||||
derived = id_map.ToQuery(indexed.derived);
|
||||
callers = id_map.ToQuery(indexed.callers);
|
||||
uses = MapIdToUsr(id_map, indexed.uses);
|
||||
}
|
||||
|
||||
@ -438,6 +434,9 @@ QueryVarId IdMap::ToQuery(IndexVarId id) const {
|
||||
assert(cached_var_ids_.find(id.id) != cached_var_ids_.end());
|
||||
return QueryVarId(cached_var_ids_.find(id.id)->second);
|
||||
}
|
||||
QueryFuncRef IdMap::ToQuery(IndexFuncRef ref) const {
|
||||
return QueryFuncRef(ToQuery(ref.id), ToQuery(ref.loc));
|
||||
}
|
||||
|
||||
optional<QueryableLocation> IdMap::ToQuery(optional<Range> range) const {
|
||||
if (!range)
|
||||
@ -459,6 +458,11 @@ optional<QueryVarId> IdMap::ToQuery(optional<IndexVarId> id) const {
|
||||
return nullopt;
|
||||
return ToQuery(id.value());
|
||||
}
|
||||
optional<QueryFuncRef> IdMap::ToQuery(optional<IndexFuncRef> ref) const {
|
||||
if (!ref)
|
||||
return nullopt;
|
||||
return ToQuery(ref.value());
|
||||
}
|
||||
|
||||
template<typename In, typename Out>
|
||||
std::vector<Out> ToQueryTransform(const IdMap& id_map, const std::vector<In>& input) {
|
||||
@ -480,6 +484,9 @@ std::vector<QueryFuncId> IdMap::ToQuery(std::vector<IndexFuncId> ids) const {
|
||||
std::vector<QueryVarId> IdMap::ToQuery(std::vector<IndexVarId> ids) const {
|
||||
return ToQueryTransform<IndexVarId, QueryVarId>(*this, ids);
|
||||
}
|
||||
std::vector<QueryFuncRef> IdMap::ToQuery(std::vector<IndexFuncRef> refs) const {
|
||||
return ToQueryTransform<IndexFuncRef, QueryFuncRef>(*this, refs);
|
||||
}
|
||||
|
||||
SymbolIdx IdMap::ToSymbol(IndexTypeId id) const {
|
||||
return SymbolIdx(SymbolKind::Type, ToQuery(id).id);
|
||||
@ -596,10 +603,10 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m
|
||||
if (previous_remapped_def != current_remapped_def)
|
||||
funcs_def_update.push_back(current_remapped_def);
|
||||
|
||||
PROCESS_UPDATE_DIFF(funcs_declarations, declarations, QueryableLocation);
|
||||
PROCESS_UPDATE_DIFF(funcs_derived, derived, Usr);
|
||||
PROCESS_UPDATE_DIFF(funcs_callers, callers, UsrRef);
|
||||
PROCESS_UPDATE_DIFF(funcs_uses, uses, QueryableLocation);
|
||||
PROCESS_UPDATE_DIFF2(funcs_declarations, declarations, QueryableLocation);
|
||||
PROCESS_UPDATE_DIFF2(funcs_derived, derived, QueryFuncId);
|
||||
PROCESS_UPDATE_DIFF2(funcs_callers, callers, QueryFuncRef);
|
||||
PROCESS_UPDATE_DIFF2(funcs_uses, uses, QueryableLocation);
|
||||
});
|
||||
|
||||
// Variables
|
||||
|
28
src/query.h
28
src/query.h
@ -88,6 +88,21 @@ struct SymbolRef {
|
||||
}
|
||||
};
|
||||
|
||||
struct QueryFuncRef {
|
||||
QueryFuncId id;
|
||||
QueryableLocation loc;
|
||||
|
||||
QueryFuncRef(QueryFuncId id, QueryableLocation loc) : id(id), loc(loc) {}
|
||||
|
||||
bool operator==(const QueryFuncRef& that) const {
|
||||
return id == that.id && loc == that.loc;
|
||||
}
|
||||
bool operator!=(const QueryFuncRef& that) const { return !(*this == that); }
|
||||
bool operator<(const QueryFuncRef& that) const {
|
||||
return id < that.id && loc.range.start < that.loc.range.start;
|
||||
}
|
||||
};
|
||||
|
||||
struct UsrRef {
|
||||
Usr usr;
|
||||
QueryableLocation loc;
|
||||
@ -175,16 +190,16 @@ struct QueryableTypeDef {
|
||||
};
|
||||
|
||||
struct QueryableFuncDef {
|
||||
using DefUpdate = FuncDefDefinitionData<Usr, Usr, Usr, UsrRef, QueryableLocation>;
|
||||
using DefUpdate = FuncDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryFuncRef, QueryableLocation>;
|
||||
using DeclarationsUpdate = MergeableUpdate<QueryableLocation>;
|
||||
using DerivedUpdate = MergeableUpdate<Usr>;
|
||||
using CallersUpdate = MergeableUpdate<UsrRef>;
|
||||
using DerivedUpdate = MergeableUpdate<QueryFuncId>;
|
||||
using CallersUpdate = MergeableUpdate<QueryFuncRef>;
|
||||
using UsesUpdate = MergeableUpdate<QueryableLocation>;
|
||||
|
||||
DefUpdate def;
|
||||
std::vector<QueryableLocation> declarations;
|
||||
std::vector<Usr> derived;
|
||||
std::vector<UsrRef> callers;
|
||||
std::vector<QueryFuncId> derived;
|
||||
std::vector<QueryFuncRef> callers;
|
||||
std::vector<QueryableLocation> uses;
|
||||
size_t qualified_name_idx = -1;
|
||||
|
||||
@ -299,14 +314,17 @@ struct IdMap {
|
||||
QueryTypeId ToQuery(IndexTypeId id) const;
|
||||
QueryFuncId ToQuery(IndexFuncId id) const;
|
||||
QueryVarId ToQuery(IndexVarId id) const;
|
||||
QueryFuncRef ToQuery(IndexFuncRef ref) const;
|
||||
optional<QueryableLocation> ToQuery(optional<Range> range) const;
|
||||
optional<QueryTypeId> ToQuery(optional<IndexTypeId> id) const;
|
||||
optional<QueryFuncId> ToQuery(optional<IndexFuncId> id) const;
|
||||
optional<QueryVarId> ToQuery(optional<IndexVarId> id) const;
|
||||
optional<QueryFuncRef> ToQuery(optional<IndexFuncRef> ref) const;
|
||||
std::vector<QueryableLocation> ToQuery(std::vector<Range> ranges) const;
|
||||
std::vector<QueryTypeId> ToQuery(std::vector<IndexTypeId> ids) const;
|
||||
std::vector<QueryFuncId> ToQuery(std::vector<IndexFuncId> ids) const;
|
||||
std::vector<QueryVarId> ToQuery(std::vector<IndexVarId> ids) const;
|
||||
std::vector<QueryFuncRef> ToQuery(std::vector<IndexFuncRef> refs) const;
|
||||
|
||||
SymbolIdx ToSymbol(IndexTypeId id) const;
|
||||
SymbolIdx ToSymbol(IndexFuncId id) const;
|
||||
|
Loading…
Reference in New Issue
Block a user