mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 09:50:26 +00:00
Simplify EachWithGen
This commit is contained in:
parent
2c787fe1fe
commit
1349cbfde3
@ -61,7 +61,7 @@ ExpandNode(QueryDatabase* db, WorkingFiles* working_files, QueryTypeId root) {
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
std::vector<Out_CqueryMemberHierarchy::Entry> ret;
|
std::vector<Out_CqueryMemberHierarchy::Entry> ret;
|
||||||
EachWithGen<QueryVar>(db->vars, root_type.def->vars, [&](QueryVar& var) {
|
EachWithGen(db->vars, root_type.def->vars, [&](QueryVar& var) {
|
||||||
Out_CqueryMemberHierarchy::Entry entry;
|
Out_CqueryMemberHierarchy::Entry entry;
|
||||||
entry.name = var.def->ShortName();
|
entry.name = var.def->ShortName();
|
||||||
// FIXME WithGen
|
// FIXME WithGen
|
||||||
|
@ -34,15 +34,14 @@ BuildParentInheritanceHierarchyForType(QueryDatabase* db,
|
|||||||
std::vector<Out_CqueryTypeHierarchyTree::TypeEntry> parent_entries;
|
std::vector<Out_CqueryTypeHierarchyTree::TypeEntry> parent_entries;
|
||||||
parent_entries.reserve(root_type.def->parents.size());
|
parent_entries.reserve(root_type.def->parents.size());
|
||||||
|
|
||||||
EachWithGen<QueryType>(
|
EachWithGen(db->types, root_type.def->parents, [&](QueryType& parent_type) {
|
||||||
db->types, root_type.def->parents, [&](QueryType& parent_type) {
|
|
||||||
Out_CqueryTypeHierarchyTree::TypeEntry parent_entry;
|
Out_CqueryTypeHierarchyTree::TypeEntry parent_entry;
|
||||||
parent_entry.name = parent_type.def->detailed_name;
|
parent_entry.name = parent_type.def->detailed_name;
|
||||||
if (parent_type.def->definition_spelling)
|
if (parent_type.def->definition_spelling)
|
||||||
parent_entry.location = GetLsLocation(
|
parent_entry.location = GetLsLocation(
|
||||||
db, working_files, *parent_type.def->definition_spelling);
|
db, working_files, *parent_type.def->definition_spelling);
|
||||||
parent_entry.children = BuildParentInheritanceHierarchyForType(
|
parent_entry.children =
|
||||||
db, working_files, parent_type);
|
BuildParentInheritanceHierarchyForType(db, working_files, parent_type);
|
||||||
|
|
||||||
parent_entries.push_back(parent_entry);
|
parent_entries.push_back(parent_entry);
|
||||||
});
|
});
|
||||||
@ -74,7 +73,7 @@ BuildInheritanceHierarchyForType(QueryDatabase* db,
|
|||||||
entry.children.push_back(base);
|
entry.children.push_back(base);
|
||||||
|
|
||||||
// Add derived.
|
// Add derived.
|
||||||
EachWithGen<QueryType>(db->types, root_type.derived, [&](QueryType& type) {
|
EachWithGen(db->types, root_type.derived, [&](QueryType& type) {
|
||||||
auto derived_entry =
|
auto derived_entry =
|
||||||
BuildInheritanceHierarchyForType(db, working_files, type);
|
BuildInheritanceHierarchyForType(db, working_files, type);
|
||||||
if (derived_entry)
|
if (derived_entry)
|
||||||
|
@ -353,8 +353,7 @@ struct TextDocumentCodeActionHandler
|
|||||||
// Get implementation file.
|
// Get implementation file.
|
||||||
Out_TextDocumentCodeAction::Command command;
|
Out_TextDocumentCodeAction::Command command;
|
||||||
|
|
||||||
EachWithGen<QueryFunc>(db->funcs, type.def->funcs, [&](QueryFunc&
|
EachWithGen(db->funcs, type.def->funcs, [&](QueryFunc& func_def) {
|
||||||
func_def) {
|
|
||||||
if (func_def.def->definition_extent)
|
if (func_def.def->definition_extent)
|
||||||
return;
|
return;
|
||||||
EnsureImplFile(db, file_id, impl_uri /*out*/, impl_file_id /*out*/);
|
EnsureImplFile(db, file_id, impl_uri /*out*/, impl_file_id /*out*/);
|
||||||
|
@ -73,8 +73,8 @@ void EmitDiagnostics(WorkingFiles* working_files,
|
|||||||
std::string path,
|
std::string path,
|
||||||
std::vector<lsDiagnostic> diagnostics);
|
std::vector<lsDiagnostic> diagnostics);
|
||||||
|
|
||||||
template <typename Q>
|
template <typename Q, typename Fn>
|
||||||
void EachWithGen(std::vector<Q>& collection, WithGen<Id<Q>> x, std::function<void(Q&)> fn) {
|
void EachWithGen(std::vector<Q>& collection, WithGen<Id<Q>> x, Fn fn) {
|
||||||
Q& obj = collection[x.value.id];
|
Q& obj = collection[x.value.id];
|
||||||
// FIXME Deprecate optional<Def> def
|
// FIXME Deprecate optional<Def> def
|
||||||
// if (obj.gen == x.gen && obj.def)
|
// if (obj.gen == x.gen && obj.def)
|
||||||
@ -82,8 +82,8 @@ void EachWithGen(std::vector<Q>& collection, WithGen<Id<Q>> x, std::function<voi
|
|||||||
fn(obj);
|
fn(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Q>
|
template <typename Q, typename Fn>
|
||||||
void EachWithGen(std::vector<Q>& collection, std::vector<WithGen<Id<Q>>>& ids, std::function<void(Q&)> fn) {
|
void EachWithGen(std::vector<Q>& collection, std::vector<WithGen<Id<Q>>>& ids, Fn fn) {
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
for (WithGen<Id<Q>> x : ids) {
|
for (WithGen<Id<Q>> x : ids) {
|
||||||
Q& obj = collection[x.value.id];
|
Q& obj = collection[x.value.id];
|
||||||
|
Loading…
Reference in New Issue
Block a user