mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 09:05:10 +00:00
Cleanup call tree appearance
- Use up/down icons instead of [B] and [D] - Don't show column number - Show declaring type instead of path if applicable
This commit is contained in:
parent
475afc77a5
commit
1e995dc30e
@ -1664,17 +1664,22 @@ struct Ipc_CqueryCallTreeExpand : public IpcMessage<Ipc_CqueryCallTreeExpand> {
|
|||||||
MAKE_REFLECT_STRUCT(Ipc_CqueryCallTreeExpand::Params, usr);
|
MAKE_REFLECT_STRUCT(Ipc_CqueryCallTreeExpand::Params, usr);
|
||||||
MAKE_REFLECT_STRUCT(Ipc_CqueryCallTreeExpand, id, params);
|
MAKE_REFLECT_STRUCT(Ipc_CqueryCallTreeExpand, id, params);
|
||||||
struct Out_CqueryCallTree : public lsOutMessage<Out_CqueryCallTree> {
|
struct Out_CqueryCallTree : public lsOutMessage<Out_CqueryCallTree> {
|
||||||
|
enum class CallType {
|
||||||
|
Direct = 0, Base = 1, Derived = 2
|
||||||
|
};
|
||||||
struct CallEntry {
|
struct CallEntry {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string usr;
|
std::string usr;
|
||||||
lsLocation location;
|
lsLocation location;
|
||||||
bool hasCallers = true;
|
bool hasCallers = true;
|
||||||
|
CallType callType = CallType::Direct;
|
||||||
};
|
};
|
||||||
|
|
||||||
lsRequestId id;
|
lsRequestId id;
|
||||||
NonElidedVector<CallEntry> result;
|
NonElidedVector<CallEntry> result;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Out_CqueryCallTree::CallEntry, name, usr, location, hasCallers);
|
MAKE_REFLECT_TYPE_PROXY(Out_CqueryCallTree::CallType, int);
|
||||||
|
MAKE_REFLECT_STRUCT(Out_CqueryCallTree::CallEntry, name, usr, location, hasCallers, callType);
|
||||||
MAKE_REFLECT_STRUCT(Out_CqueryCallTree, jsonrpc, id, result);
|
MAKE_REFLECT_STRUCT(Out_CqueryCallTree, jsonrpc, id, result);
|
||||||
|
|
||||||
// Vars, Callers, Derived, GotoParent
|
// Vars, Callers, Derived, GotoParent
|
||||||
|
@ -752,19 +752,29 @@ NonElidedVector<Out_CqueryCallTree::CallEntry> BuildExpandCallTree(QueryDatabase
|
|||||||
if (!root_func)
|
if (!root_func)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto format_location = [](const lsLocation& location) -> std::string {
|
auto format_location = [&](const lsLocation& location, optional<QueryTypeId> declaring_type) -> std::string {
|
||||||
std::string path = location.uri.GetPath();
|
std::string base;
|
||||||
size_t last_index = path.find_last_of('/');
|
|
||||||
if (last_index != std::string::npos)
|
|
||||||
path = path.substr(last_index + 1);
|
|
||||||
|
|
||||||
return path + ":" + std::to_string(location.range.start.line + 1) + ":" + std::to_string(location.range.start.character + 1);
|
if (declaring_type) {
|
||||||
|
optional<QueryType> type = db->types[declaring_type->id];
|
||||||
|
if (type)
|
||||||
|
base = type->def.detailed_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (base.empty()) {
|
||||||
|
base = location.uri.GetPath();
|
||||||
|
size_t last_index = base.find_last_of('/');
|
||||||
|
if (last_index != std::string::npos)
|
||||||
|
base = base.substr(last_index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return base + ":" + std::to_string(location.range.start.line + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
NonElidedVector<Out_CqueryCallTree::CallEntry> result;
|
NonElidedVector<Out_CqueryCallTree::CallEntry> result;
|
||||||
std::unordered_set<QueryLocation> seen_locations;
|
std::unordered_set<QueryLocation> seen_locations;
|
||||||
|
|
||||||
auto handle_caller = [&](const std::string& prefix, QueryFuncRef caller) {
|
auto handle_caller = [&](QueryFuncRef caller, Out_CqueryCallTree::CallType call_type) {
|
||||||
optional<lsLocation> call_location = GetLsLocation(db, working_files, caller.loc);
|
optional<lsLocation> call_location = GetLsLocation(db, working_files, caller.loc);
|
||||||
if (!call_location)
|
if (!call_location)
|
||||||
return;
|
return;
|
||||||
@ -793,10 +803,11 @@ NonElidedVector<Out_CqueryCallTree::CallEntry> BuildExpandCallTree(QueryDatabase
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Out_CqueryCallTree::CallEntry call_entry;
|
Out_CqueryCallTree::CallEntry call_entry;
|
||||||
call_entry.name = prefix + call_func->def.short_name + " (" + format_location(*call_location) + ")";
|
call_entry.name = call_func->def.short_name + " (" + format_location(*call_location, call_func->def.declaring_type) + ")";
|
||||||
call_entry.usr = call_func->def.usr;
|
call_entry.usr = call_func->def.usr;
|
||||||
call_entry.location = *call_location;
|
call_entry.location = *call_location;
|
||||||
call_entry.hasCallers = HasCallersOnSelfOrBaseOrDerived(db, *call_func);
|
call_entry.hasCallers = HasCallersOnSelfOrBaseOrDerived(db, *call_func);
|
||||||
|
call_entry.callType = call_type;
|
||||||
result.push_back(call_entry);
|
result.push_back(call_entry);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -807,6 +818,7 @@ NonElidedVector<Out_CqueryCallTree::CallEntry> BuildExpandCallTree(QueryDatabase
|
|||||||
call_entry.usr = "no_usr";
|
call_entry.usr = "no_usr";
|
||||||
call_entry.location = *call_location;
|
call_entry.location = *call_location;
|
||||||
call_entry.hasCallers = false;
|
call_entry.hasCallers = false;
|
||||||
|
call_entry.callType = call_type;
|
||||||
result.push_back(call_entry);
|
result.push_back(call_entry);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -816,16 +828,16 @@ NonElidedVector<Out_CqueryCallTree::CallEntry> BuildExpandCallTree(QueryDatabase
|
|||||||
result.reserve(root_func->callers.size() + base_callers.size() + derived_callers.size());
|
result.reserve(root_func->callers.size() + base_callers.size() + derived_callers.size());
|
||||||
|
|
||||||
for (QueryFuncRef caller : root_func->callers)
|
for (QueryFuncRef caller : root_func->callers)
|
||||||
handle_caller("", caller);
|
handle_caller(caller, Out_CqueryCallTree::CallType::Direct);
|
||||||
for (QueryFuncRef caller : base_callers) {
|
for (QueryFuncRef caller : base_callers) {
|
||||||
// Do not show calls to the base function coming from this function.
|
// Do not show calls to the base function coming from this function.
|
||||||
if (caller.id_ == root)
|
if (caller.id_ == root)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
handle_caller("[B] ", caller);
|
handle_caller(caller, Out_CqueryCallTree::CallType::Base);
|
||||||
}
|
}
|
||||||
for (QueryFuncRef caller : derived_callers)
|
for (QueryFuncRef caller : derived_callers)
|
||||||
handle_caller("[D] ", caller);
|
handle_caller(caller, Out_CqueryCallTree::CallType::Derived);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user