mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-03 22:04:24 +00:00 
			
		
		
		
	Simplify hierarchies
This commit is contained in:
		
							parent
							
								
									95797be730
								
							
						
					
					
						commit
						c166f3bca8
					
				@ -83,7 +83,7 @@ MAKE_REFLECT_STRUCT(Out_CqueryCallHierarchy::Entry,
 | 
				
			|||||||
                    children);
 | 
					                    children);
 | 
				
			||||||
MAKE_REFLECT_STRUCT(Out_CqueryCallHierarchy, jsonrpc, id, result);
 | 
					MAKE_REFLECT_STRUCT(Out_CqueryCallHierarchy, jsonrpc, id, result);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Expand(MessageHandler* m,
 | 
					bool Expand(MessageHandler* m,
 | 
				
			||||||
            Out_CqueryCallHierarchy::Entry* entry,
 | 
					            Out_CqueryCallHierarchy::Entry* entry,
 | 
				
			||||||
            bool callee,
 | 
					            bool callee,
 | 
				
			||||||
            CallType call_type,
 | 
					            CallType call_type,
 | 
				
			||||||
@ -93,28 +93,16 @@ void Expand(MessageHandler* m,
 | 
				
			|||||||
  const QueryFunc::Def* def = func.AnyDef();
 | 
					  const QueryFunc::Def* def = func.AnyDef();
 | 
				
			||||||
  entry->numChildren = 0;
 | 
					  entry->numChildren = 0;
 | 
				
			||||||
  if (!def)
 | 
					  if (!def)
 | 
				
			||||||
    return;
 | 
					    return false;
 | 
				
			||||||
  auto handle = [&](Use use, CallType call_type) {
 | 
					  auto handle = [&](Use use, CallType call_type) {
 | 
				
			||||||
    entry->numChildren++;
 | 
					    entry->numChildren++;
 | 
				
			||||||
    if (levels > 0) {
 | 
					    if (levels > 0) {
 | 
				
			||||||
      QueryFunc& rel_func = m->db->GetFunc(use);
 | 
					 | 
				
			||||||
      const QueryFunc::Def* rel_def = rel_func.AnyDef();
 | 
					 | 
				
			||||||
      if (!rel_def)
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
      if (optional<lsLocation> loc =
 | 
					 | 
				
			||||||
              GetLsLocation(m->db, m->working_files, use)) {
 | 
					 | 
				
			||||||
      Out_CqueryCallHierarchy::Entry entry1;
 | 
					      Out_CqueryCallHierarchy::Entry entry1;
 | 
				
			||||||
      entry1.id = QueryFuncId(use.id);
 | 
					      entry1.id = QueryFuncId(use.id);
 | 
				
			||||||
          if (detailed_name)
 | 
					 | 
				
			||||||
            entry1.name = rel_def->detailed_name;
 | 
					 | 
				
			||||||
          else
 | 
					 | 
				
			||||||
            entry1.name = rel_def->ShortName();
 | 
					 | 
				
			||||||
          entry1.location = *loc;
 | 
					 | 
				
			||||||
      entry1.callType = call_type;
 | 
					      entry1.callType = call_type;
 | 
				
			||||||
          Expand(m, &entry1, callee, call_type, detailed_name, levels - 1);
 | 
					      if (Expand(m, &entry1, callee, call_type, detailed_name, levels - 1))
 | 
				
			||||||
        entry->children.push_back(std::move(entry1));
 | 
					        entry->children.push_back(std::move(entry1));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  auto handle_uses = [&](const QueryFunc& func, CallType call_type) {
 | 
					  auto handle_uses = [&](const QueryFunc& func, CallType call_type) {
 | 
				
			||||||
    if (callee) {
 | 
					    if (callee) {
 | 
				
			||||||
@ -131,6 +119,15 @@ void Expand(MessageHandler* m,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  std::unordered_set<Usr> seen;
 | 
					  std::unordered_set<Usr> seen;
 | 
				
			||||||
  std::vector<const QueryFunc*> stack;
 | 
					  std::vector<const QueryFunc*> stack;
 | 
				
			||||||
 | 
					  if (detailed_name)
 | 
				
			||||||
 | 
					    entry->name = def->detailed_name;
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    entry->name = def->ShortName();
 | 
				
			||||||
 | 
					  if (def->spell) {
 | 
				
			||||||
 | 
					    if (optional<lsLocation> loc =
 | 
				
			||||||
 | 
					        GetLsLocation(m->db, m->working_files, *def->spell))
 | 
				
			||||||
 | 
					      entry->location = *loc;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  handle_uses(func, CallType::Direct);
 | 
					  handle_uses(func, CallType::Direct);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Callers/callees of base functions.
 | 
					  // Callers/callees of base functions.
 | 
				
			||||||
@ -167,6 +164,7 @@ void Expand(MessageHandler* m,
 | 
				
			|||||||
      });
 | 
					      });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct CqueryCallHierarchyInitialHandler
 | 
					struct CqueryCallHierarchyInitialHandler
 | 
				
			||||||
@ -182,15 +180,7 @@ struct CqueryCallHierarchyInitialHandler
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    Out_CqueryCallHierarchy::Entry entry;
 | 
					    Out_CqueryCallHierarchy::Entry entry;
 | 
				
			||||||
    entry.id = root_id;
 | 
					    entry.id = root_id;
 | 
				
			||||||
    if (detailed_name)
 | 
					    entry.callType = CallType::Direct;
 | 
				
			||||||
      entry.name = def->detailed_name;
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
      entry.name = def->ShortName();
 | 
					 | 
				
			||||||
    if (def->spell) {
 | 
					 | 
				
			||||||
      if (optional<lsLocation> loc =
 | 
					 | 
				
			||||||
          GetLsLocation(db, working_files, *def->spell))
 | 
					 | 
				
			||||||
        entry.location = *loc;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    Expand(this, &entry, callee, call_type, detailed_name, levels);
 | 
					    Expand(this, &entry, callee, call_type, detailed_name, levels);
 | 
				
			||||||
    return entry;
 | 
					    return entry;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -231,7 +221,7 @@ struct CqueryCallHierarchyExpandHandler
 | 
				
			|||||||
    if (params.id) {
 | 
					    if (params.id) {
 | 
				
			||||||
      Out_CqueryCallHierarchy::Entry entry;
 | 
					      Out_CqueryCallHierarchy::Entry entry;
 | 
				
			||||||
      entry.id = *params.id;
 | 
					      entry.id = *params.id;
 | 
				
			||||||
      // entry.name is empty as it is known by the client.
 | 
					      entry.callType = CallType::Direct;
 | 
				
			||||||
      if (entry.id.id < db->funcs.size())
 | 
					      if (entry.id.id < db->funcs.size())
 | 
				
			||||||
        Expand(this, &entry, params.callee, params.callType,
 | 
					        Expand(this, &entry, params.callee, params.callType,
 | 
				
			||||||
               params.detailedName, params.levels);
 | 
					               params.detailedName, params.levels);
 | 
				
			||||||
 | 
				
			|||||||
@ -100,7 +100,6 @@ bool ExpandHelper(MessageHandler* m,
 | 
				
			|||||||
      entry->location = *loc;
 | 
					      entry->location = *loc;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (derived) {
 | 
					  if (derived) {
 | 
				
			||||||
    entry->numChildren = int(entity.derived.size());
 | 
					 | 
				
			||||||
    if (levels > 0) {
 | 
					    if (levels > 0) {
 | 
				
			||||||
      for (auto id : entity.derived) {
 | 
					      for (auto id : entity.derived) {
 | 
				
			||||||
        Out_CqueryInheritanceHierarchy::Entry entry1;
 | 
					        Out_CqueryInheritanceHierarchy::Entry entry1;
 | 
				
			||||||
@ -110,9 +109,9 @@ bool ExpandHelper(MessageHandler* m,
 | 
				
			|||||||
          entry->children.push_back(std::move(entry1));
 | 
					          entry->children.push_back(std::move(entry1));
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      entry->numChildren = int(entry->children.size());
 | 
					      entry->numChildren = int(entry->children.size());
 | 
				
			||||||
    }
 | 
					    } else
 | 
				
			||||||
 | 
					      entry->numChildren = int(entity.derived.size());
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    entry->numChildren = int(def->bases.size());
 | 
					 | 
				
			||||||
    if (levels > 0) {
 | 
					    if (levels > 0) {
 | 
				
			||||||
      for (auto id : def->bases) {
 | 
					      for (auto id : def->bases) {
 | 
				
			||||||
        Out_CqueryInheritanceHierarchy::Entry entry1;
 | 
					        Out_CqueryInheritanceHierarchy::Entry entry1;
 | 
				
			||||||
@ -122,7 +121,8 @@ bool ExpandHelper(MessageHandler* m,
 | 
				
			|||||||
          entry->children.push_back(std::move(entry1));
 | 
					          entry->children.push_back(std::move(entry1));
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      entry->numChildren = int(entry->children.size());
 | 
					      entry->numChildren = int(entry->children.size());
 | 
				
			||||||
    }
 | 
					    } else
 | 
				
			||||||
 | 
					      entry->numChildren = int(def->bases.size());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return true;
 | 
					  return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -62,7 +62,7 @@ MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy::Entry,
 | 
				
			|||||||
                    children);
 | 
					                    children);
 | 
				
			||||||
MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy, jsonrpc, id, result);
 | 
					MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy, jsonrpc, id, result);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Expand(MessageHandler* m,
 | 
					bool Expand(MessageHandler* m,
 | 
				
			||||||
            Out_CqueryMemberHierarchy::Entry* entry,
 | 
					            Out_CqueryMemberHierarchy::Entry* entry,
 | 
				
			||||||
            bool detailed_name,
 | 
					            bool detailed_name,
 | 
				
			||||||
            int levels) {
 | 
					            int levels) {
 | 
				
			||||||
@ -100,13 +100,12 @@ void Expand(MessageHandler* m,
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  if (!def) {
 | 
					  if (!def) {
 | 
				
			||||||
    entry->numChildren = 0;
 | 
					    entry->numChildren = 0;
 | 
				
			||||||
    return;
 | 
					    return false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (detailed_name)
 | 
					  if (detailed_name)
 | 
				
			||||||
    entry->name = def->detailed_name;
 | 
					    entry->name = def->detailed_name;
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    entry->name = def->ShortName();
 | 
					    entry->name = def->ShortName();
 | 
				
			||||||
  entry->numChildren = int(def->vars.size());
 | 
					 | 
				
			||||||
  if (levels > 0) {
 | 
					  if (levels > 0) {
 | 
				
			||||||
    EachDefinedEntity(m->db->vars, def->vars, [&](QueryVar& var) {
 | 
					    EachDefinedEntity(m->db->vars, def->vars, [&](QueryVar& var) {
 | 
				
			||||||
      const QueryVar::Def* def1 = var.AnyDef();
 | 
					      const QueryVar::Def* def1 = var.AnyDef();
 | 
				
			||||||
@ -123,11 +122,13 @@ void Expand(MessageHandler* m,
 | 
				
			|||||||
            GetLsLocation(m->db, m->working_files, *def1->spell))
 | 
					            GetLsLocation(m->db, m->working_files, *def1->spell))
 | 
				
			||||||
          entry1.location = *loc;
 | 
					          entry1.location = *loc;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      Expand(m, &entry1, detailed_name, levels - 1);
 | 
					      if (Expand(m, &entry1, detailed_name, levels - 1))
 | 
				
			||||||
        entry->children.push_back(std::move(entry1));
 | 
					        entry->children.push_back(std::move(entry1));
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    entry->numChildren = int(entry->children.size());
 | 
					    entry->numChildren = int(entry->children.size());
 | 
				
			||||||
  }
 | 
					  } else
 | 
				
			||||||
 | 
					    entry->numChildren = int(def->vars.size());
 | 
				
			||||||
 | 
					  return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct CqueryMemberHierarchyInitialHandler
 | 
					struct CqueryMemberHierarchyInitialHandler
 | 
				
			||||||
@ -193,8 +194,8 @@ struct CqueryMemberHierarchyExpandHandler
 | 
				
			|||||||
      Out_CqueryMemberHierarchy::Entry entry;
 | 
					      Out_CqueryMemberHierarchy::Entry entry;
 | 
				
			||||||
      entry.id = *request->params.id;
 | 
					      entry.id = *request->params.id;
 | 
				
			||||||
      // entry.name is empty as it is known by the client.
 | 
					      // entry.name is empty as it is known by the client.
 | 
				
			||||||
      if (entry.id.id < db->types.size())
 | 
					      if (entry.id.id < db->types.size() &&
 | 
				
			||||||
        Expand(this, &entry, params.detailedName, params.levels);
 | 
					          Expand(this, &entry, params.detailedName, params.levels))
 | 
				
			||||||
        out.result = std::move(entry);
 | 
					        out.result = std::move(entry);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user