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