diff --git a/src/language_server_api.h b/src/language_server_api.h index d009c28c..547b696b 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -1664,17 +1664,22 @@ struct Ipc_CqueryCallTreeExpand : public IpcMessage { MAKE_REFLECT_STRUCT(Ipc_CqueryCallTreeExpand::Params, usr); MAKE_REFLECT_STRUCT(Ipc_CqueryCallTreeExpand, id, params); struct Out_CqueryCallTree : public lsOutMessage { + enum class CallType { + Direct = 0, Base = 1, Derived = 2 + }; struct CallEntry { std::string name; std::string usr; lsLocation location; bool hasCallers = true; + CallType callType = CallType::Direct; }; lsRequestId id; NonElidedVector 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); // Vars, Callers, Derived, GotoParent diff --git a/src/query_utils.cc b/src/query_utils.cc index 29b159a6..ccbf8004 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -752,19 +752,29 @@ NonElidedVector BuildExpandCallTree(QueryDatabase if (!root_func) return {}; - auto format_location = [](const lsLocation& location) -> std::string { - std::string path = location.uri.GetPath(); - size_t last_index = path.find_last_of('/'); - if (last_index != std::string::npos) - path = path.substr(last_index + 1); + auto format_location = [&](const lsLocation& location, optional declaring_type) -> std::string { + std::string base; - return path + ":" + std::to_string(location.range.start.line + 1) + ":" + std::to_string(location.range.start.character + 1); + if (declaring_type) { + optional 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 result; std::unordered_set seen_locations; - auto handle_caller = [&](const std::string& prefix, QueryFuncRef caller) { + auto handle_caller = [&](QueryFuncRef caller, Out_CqueryCallTree::CallType call_type) { optional call_location = GetLsLocation(db, working_files, caller.loc); if (!call_location) return; @@ -793,10 +803,11 @@ NonElidedVector BuildExpandCallTree(QueryDatabase return; 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.location = *call_location; call_entry.hasCallers = HasCallersOnSelfOrBaseOrDerived(db, *call_func); + call_entry.callType = call_type; result.push_back(call_entry); } else { @@ -807,6 +818,7 @@ NonElidedVector BuildExpandCallTree(QueryDatabase call_entry.usr = "no_usr"; call_entry.location = *call_location; call_entry.hasCallers = false; + call_entry.callType = call_type; result.push_back(call_entry); } }; @@ -816,16 +828,16 @@ NonElidedVector BuildExpandCallTree(QueryDatabase result.reserve(root_func->callers.size() + base_callers.size() + derived_callers.size()); for (QueryFuncRef caller : root_func->callers) - handle_caller("", caller); + handle_caller(caller, Out_CqueryCallTree::CallType::Direct); for (QueryFuncRef caller : base_callers) { // Do not show calls to the base function coming from this function. if (caller.id_ == root) continue; - handle_caller("[B] ", caller); + handle_caller(caller, Out_CqueryCallTree::CallType::Base); } for (QueryFuncRef caller : derived_callers) - handle_caller("[D] ", caller); + handle_caller(caller, Out_CqueryCallTree::CallType::Derived); return result; }