diff --git a/src/command_line.cc b/src/command_line.cc index 3817f41d..c85fa86a 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -342,12 +342,9 @@ void LaunchStdinLoop(Config* config, case IpcId::WorkspaceSymbol: case IpcId::CqueryFileInfo: case IpcId::CqueryFreshenIndex: - case IpcId::CqueryCallHierarchyInitial: - case IpcId::CqueryCallHierarchyExpand: - case IpcId::CqueryInheritanceHierarchyInitial: - case IpcId::CqueryInheritanceHierarchyExpand: - case IpcId::CqueryMemberHierarchyInitial: - case IpcId::CqueryMemberHierarchyExpand: + case IpcId::CqueryCallHierarchy: + case IpcId::CqueryInheritanceHierarchy: + case IpcId::CqueryMemberHierarchy: case IpcId::CqueryVars: case IpcId::CqueryCallers: case IpcId::CqueryBase: diff --git a/src/ipc.cc b/src/ipc.cc index 0ecb5e8e..f038a30c 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -70,18 +70,12 @@ const char* IpcIdToString(IpcId id) { return "$cquery/fileInfo"; case IpcId::CqueryFreshenIndex: return "$cquery/freshenIndex"; - case IpcId::CqueryCallHierarchyInitial: - return "$cquery/callHierarchyInitial"; - case IpcId::CqueryCallHierarchyExpand: - return "$cquery/callHierarchyExpand"; - case IpcId::CqueryInheritanceHierarchyInitial: - return "$cquery/inheritanceHierarchyInitial"; - case IpcId::CqueryInheritanceHierarchyExpand: - return "$cquery/inheritanceHierarchyExpand"; - case IpcId::CqueryMemberHierarchyInitial: - return "$cquery/memberHierarchyInitial"; - case IpcId::CqueryMemberHierarchyExpand: - return "$cquery/memberHierarchyExpand"; + case IpcId::CqueryCallHierarchy: + return "$cquery/callHierarchy"; + case IpcId::CqueryInheritanceHierarchy: + return "$cquery/inheritanceHierarchy"; + case IpcId::CqueryMemberHierarchy: + return "$cquery/memberHierarchy"; case IpcId::CqueryVars: return "$cquery/vars"; case IpcId::CqueryCallers: diff --git a/src/ipc.h b/src/ipc.h index 7987ae2a..395115a1 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -48,12 +48,9 @@ enum class IpcId : int { CqueryFileInfo, CqueryFreshenIndex, // Messages used in tree views. - CqueryCallHierarchyInitial, - CqueryCallHierarchyExpand, - CqueryInheritanceHierarchyInitial, - CqueryInheritanceHierarchyExpand, - CqueryMemberHierarchyInitial, - CqueryMemberHierarchyExpand, + CqueryCallHierarchy, + CqueryInheritanceHierarchy, + CqueryMemberHierarchy, // These are like DocumentReferences but show different types of data. CqueryVars, // Show all variables of a type. CqueryCallers, // Show all callers of a function. diff --git a/src/messages/cquery_call_hierarchy.cc b/src/messages/cquery_call_hierarchy.cc index 381cba67..1a8e7c41 100644 --- a/src/messages/cquery_call_hierarchy.cc +++ b/src/messages/cquery_call_hierarchy.cc @@ -12,12 +12,17 @@ bool operator&(CallType lhs, CallType rhs) { return uint8_t(lhs) & uint8_t(rhs); } -struct Ipc_CqueryCallHierarchyInitial - : public RequestMessage { - const static IpcId kIpcId = IpcId::CqueryCallHierarchyInitial; +struct Ipc_CqueryCallHierarchy + : public RequestMessage { + const static IpcId kIpcId = IpcId::CqueryCallHierarchy; struct Params { + // If id is specified, expand a node; otherwise textDocument+position should + // be specified for building the root and |levels| of nodes below. lsTextDocumentIdentifier textDocument; lsPosition position; + + Maybe id; + // true: callee tree (functions called by this function); false: caller tree // (where this function is called) bool callee = false; @@ -29,36 +34,16 @@ struct Ipc_CqueryCallHierarchyInitial }; Params params; }; -MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyInitial::Params, +MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchy::Params, textDocument, position, - callee, - callType, - detailedName, - levels); -MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyInitial, id, params); -REGISTER_IPC_MESSAGE(Ipc_CqueryCallHierarchyInitial); - -struct Ipc_CqueryCallHierarchyExpand - : public RequestMessage { - const static IpcId kIpcId = IpcId::CqueryCallHierarchyExpand; - struct Params { - Maybe id; - bool callee = false; - CallType callType = CallType::Direct; - bool detailedName = false; - int levels = 1; - }; - Params params; -}; -MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyExpand::Params, id, callee, callType, detailedName, levels); -MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyExpand, id, params); -REGISTER_IPC_MESSAGE(Ipc_CqueryCallHierarchyExpand); +MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchy, id, params); +REGISTER_IPC_MESSAGE(Ipc_CqueryCallHierarchy); struct Out_CqueryCallHierarchy : public lsOutMessage { struct Entry { @@ -167,8 +152,8 @@ bool Expand(MessageHandler* m, return true; } -struct CqueryCallHierarchyInitialHandler - : BaseMessageHandler { +struct CqueryCallHierarchyHandler + : BaseMessageHandler { optional BuildInitial(QueryFuncId root_id, bool callee, CallType call_type, @@ -185,39 +170,11 @@ struct CqueryCallHierarchyInitialHandler return entry; } - void Run(Ipc_CqueryCallHierarchyInitial* request) override { - QueryFile* file; - const auto& params = request->params; - if (!FindFileOrFail(db, project, request->id, - params.textDocument.uri.GetPath(), &file)) - return; - - WorkingFile* working_file = - working_files->GetFileByFilename(file->def->path); - Out_CqueryCallHierarchy out; - out.id = request->id; - - for (SymbolRef sym : - FindSymbolsAtLocation(working_file, file, params.position)) { - if (sym.kind == SymbolKind::Func) { - out.result = - BuildInitial(QueryFuncId(sym.id), params.callee, params.callType, - params.detailedName, params.levels); - break; - } - } - - QueueManager::WriteStdout(IpcId::CqueryCallHierarchyInitial, out); - } -}; -REGISTER_MESSAGE_HANDLER(CqueryCallHierarchyInitialHandler); - -struct CqueryCallHierarchyExpandHandler - : BaseMessageHandler { - void Run(Ipc_CqueryCallHierarchyExpand* request) override { + void Run(Ipc_CqueryCallHierarchy* request) override { const auto& params = request->params; Out_CqueryCallHierarchy out; out.id = request->id; + if (params.id) { Out_CqueryCallHierarchy::Entry entry; entry.id = *params.id; @@ -226,10 +183,27 @@ struct CqueryCallHierarchyExpandHandler Expand(this, &entry, params.callee, params.callType, params.detailedName, params.levels); out.result = std::move(entry); + } else { + QueryFile* file; + if (!FindFileOrFail(db, project, request->id, + params.textDocument.uri.GetPath(), &file)) + return; + WorkingFile* working_file = + working_files->GetFileByFilename(file->def->path); + for (SymbolRef sym : + FindSymbolsAtLocation(working_file, file, params.position)) { + if (sym.kind == SymbolKind::Func) { + out.result = + BuildInitial(QueryFuncId(sym.id), params.callee, params.callType, + params.detailedName, params.levels); + break; + } + } } - QueueManager::WriteStdout(IpcId::CqueryCallHierarchyExpand, out); + QueueManager::WriteStdout(IpcId::CqueryCallHierarchy, out); } }; -REGISTER_MESSAGE_HANDLER(CqueryCallHierarchyExpandHandler); +REGISTER_MESSAGE_HANDLER(CqueryCallHierarchyHandler); + } // namespace diff --git a/src/messages/cquery_inheritance_hierarchy.cc b/src/messages/cquery_inheritance_hierarchy.cc index b7860c1b..1d702a9c 100644 --- a/src/messages/cquery_inheritance_hierarchy.cc +++ b/src/messages/cquery_inheritance_hierarchy.cc @@ -3,12 +3,18 @@ #include "queue_manager.h" namespace { -struct Ipc_CqueryInheritanceHierarchyInitial - : public RequestMessage { - const static IpcId kIpcId = IpcId::CqueryInheritanceHierarchyInitial; +struct Ipc_CqueryInheritanceHierarchy + : public RequestMessage { + const static IpcId kIpcId = IpcId::CqueryInheritanceHierarchy; struct Params { + // If id+kind are specified, expand a node; otherwise textDocument+position should + // be specified for building the root and |levels| of nodes below. lsTextDocumentIdentifier textDocument; lsPosition position; + + Maybe> id; + SymbolKind kind = SymbolKind::Invalid; + // true: derived classes/functions; false: base classes/functions bool derived = false; bool detailedName = false; @@ -17,35 +23,16 @@ struct Ipc_CqueryInheritanceHierarchyInitial Params params; }; -MAKE_REFLECT_STRUCT(Ipc_CqueryInheritanceHierarchyInitial::Params, +MAKE_REFLECT_STRUCT(Ipc_CqueryInheritanceHierarchy::Params, textDocument, position, - derived, - detailedName, - levels); -MAKE_REFLECT_STRUCT(Ipc_CqueryInheritanceHierarchyInitial, id, params); -REGISTER_IPC_MESSAGE(Ipc_CqueryInheritanceHierarchyInitial); - -struct Ipc_CqueryInheritanceHierarchyExpand - : public RequestMessage { - const static IpcId kIpcId = IpcId::CqueryInheritanceHierarchyExpand; - struct Params { - Maybe> id; - SymbolKind kind = SymbolKind::Invalid; - bool derived = false; - bool detailedName = false; - int levels = 1; - }; - Params params; -}; -MAKE_REFLECT_STRUCT(Ipc_CqueryInheritanceHierarchyExpand::Params, id, kind, derived, detailedName, levels); -MAKE_REFLECT_STRUCT(Ipc_CqueryInheritanceHierarchyExpand, id, params); -REGISTER_IPC_MESSAGE(Ipc_CqueryInheritanceHierarchyExpand); +MAKE_REFLECT_STRUCT(Ipc_CqueryInheritanceHierarchy, id, params); +REGISTER_IPC_MESSAGE(Ipc_CqueryInheritanceHierarchy); struct Out_CqueryInheritanceHierarchy : public lsOutMessage { @@ -140,8 +127,8 @@ bool Expand(MessageHandler* m, m->db->types[entry->id.id]); } -struct CqueryInheritanceHierarchyInitialHandler - : BaseMessageHandler { +struct CqueryInheritanceHierarchyHandler + : BaseMessageHandler { optional BuildInitial(SymbolRef sym, bool derived, bool detailed_name, int levels) { Out_CqueryInheritanceHierarchy::Entry entry; @@ -151,38 +138,11 @@ struct CqueryInheritanceHierarchyInitialHandler return entry; } - void Run(Ipc_CqueryInheritanceHierarchyInitial* request) override { - const auto& params = request->params; - QueryFile* file; - if (!FindFileOrFail(db, project, request->id, - params.textDocument.uri.GetPath(), &file)) - return; - - WorkingFile* working_file = - working_files->GetFileByFilename(file->def->path); - Out_CqueryInheritanceHierarchy out; - out.id = request->id; - - for (SymbolRef sym : - FindSymbolsAtLocation(working_file, file, request->params.position)) { - if (sym.kind == SymbolKind::Func || sym.kind == SymbolKind::Type) { - out.result = BuildInitial(sym, params.derived, params.detailedName, - params.levels); - break; - } - } - - QueueManager::WriteStdout(IpcId::CqueryInheritanceHierarchyInitial, out); - } -}; -REGISTER_MESSAGE_HANDLER(CqueryInheritanceHierarchyInitialHandler); - -struct CqueryInheritanceHierarchyExpandHandler - : BaseMessageHandler { - void Run(Ipc_CqueryInheritanceHierarchyExpand* request) override { + void Run(Ipc_CqueryInheritanceHierarchy* request) override { const auto& params = request->params; Out_CqueryInheritanceHierarchy out; out.id = request->id; + if (params.id) { Out_CqueryInheritanceHierarchy::Entry entry; entry.id = *params.id; @@ -193,10 +153,27 @@ struct CqueryInheritanceHierarchyExpandHandler Expand(this, &entry, params.derived, params.detailedName, params.levels)) out.result = std::move(entry); + } else { + QueryFile* file; + if (!FindFileOrFail(db, project, request->id, + params.textDocument.uri.GetPath(), &file)) + return; + WorkingFile* working_file = + working_files->GetFileByFilename(file->def->path); + + for (SymbolRef sym : + FindSymbolsAtLocation(working_file, file, request->params.position)) { + if (sym.kind == SymbolKind::Func || sym.kind == SymbolKind::Type) { + out.result = BuildInitial(sym, params.derived, params.detailedName, + params.levels); + break; + } + } } - QueueManager::WriteStdout(IpcId::CqueryInheritanceHierarchyExpand, out); + QueueManager::WriteStdout(IpcId::CqueryInheritanceHierarchy, out); } }; -REGISTER_MESSAGE_HANDLER(CqueryInheritanceHierarchyExpandHandler); +REGISTER_MESSAGE_HANDLER(CqueryInheritanceHierarchyHandler); + } // namespace diff --git a/src/messages/cquery_member_hierarchy.cc b/src/messages/cquery_member_hierarchy.cc index ff144dae..0314a425 100644 --- a/src/messages/cquery_member_hierarchy.cc +++ b/src/messages/cquery_member_hierarchy.cc @@ -3,39 +3,31 @@ #include "queue_manager.h" namespace { -struct Ipc_CqueryMemberHierarchyInitial - : public RequestMessage { - const static IpcId kIpcId = IpcId::CqueryMemberHierarchyInitial; +struct Ipc_CqueryMemberHierarchy + : public RequestMessage { + const static IpcId kIpcId = IpcId::CqueryMemberHierarchy; struct Params { + // If id is specified, expand a node; otherwise textDocument+position should + // be specified for building the root and |levels| of nodes below. lsTextDocumentIdentifier textDocument; lsPosition position; + + Maybe id; + bool detailedName = false; int levels = 1; }; Params params; }; -MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyInitial::Params, +MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchy::Params, textDocument, position, + id, detailedName, levels); -MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyInitial, id, params); -REGISTER_IPC_MESSAGE(Ipc_CqueryMemberHierarchyInitial); - -struct Ipc_CqueryMemberHierarchyExpand - : public RequestMessage { - const static IpcId kIpcId = IpcId::CqueryMemberHierarchyExpand; - struct Params { - Maybe id; - bool detailedName = false; - int levels = 1; - }; - Params params; -}; -MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyExpand::Params, id, detailedName, levels); -MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyExpand, id, params); -REGISTER_IPC_MESSAGE(Ipc_CqueryMemberHierarchyExpand); +MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchy, id, params); +REGISTER_IPC_MESSAGE(Ipc_CqueryMemberHierarchy); struct Out_CqueryMemberHierarchy : public lsOutMessage { @@ -166,8 +158,8 @@ bool Expand(MessageHandler* m, return true; } -struct CqueryMemberHierarchyInitialHandler - : BaseMessageHandler { +struct CqueryMemberHierarchyHandler + : BaseMessageHandler { optional BuildInitial(QueryFuncId root_id, bool detailed_name, int levels) { @@ -210,53 +202,11 @@ struct CqueryMemberHierarchyInitialHandler return entry; } - void Run(Ipc_CqueryMemberHierarchyInitial* request) override { - QueryFile* file; - const auto& params = request->params; - if (!FindFileOrFail(db, project, request->id, - params.textDocument.uri.GetPath(), &file)) - return; - - WorkingFile* working_file = - working_files->GetFileByFilename(file->def->path); - Out_CqueryMemberHierarchy out; - out.id = request->id; - - for (SymbolRef sym : - FindSymbolsAtLocation(working_file, file, params.position)) { - switch (sym.kind) { - case SymbolKind::Func: - out.result = BuildInitial(QueryFuncId(sym.id), params.detailedName, - params.levels); - break; - case SymbolKind::Type: - out.result = BuildInitial(QueryTypeId(sym.id), params.detailedName, - params.levels); - break; - case SymbolKind::Var: { - const QueryVar::Def* def = db->GetVar(sym).AnyDef(); - if (def && def->type) - out.result = BuildInitial(QueryTypeId(*def->type), - params.detailedName, params.levels); - break; - } - default: - continue; - } - break; - } - - QueueManager::WriteStdout(IpcId::CqueryMemberHierarchyInitial, out); - } -}; -REGISTER_MESSAGE_HANDLER(CqueryMemberHierarchyInitialHandler); - -struct CqueryMemberHierarchyExpandHandler - : BaseMessageHandler { - void Run(Ipc_CqueryMemberHierarchyExpand* request) override { + void Run(Ipc_CqueryMemberHierarchy* request) override { const auto& params = request->params; Out_CqueryMemberHierarchy out; out.id = request->id; + if (params.id) { Out_CqueryMemberHierarchy::Entry entry; entry.id = *request->params.id; @@ -264,10 +214,41 @@ struct CqueryMemberHierarchyExpandHandler if (entry.id.id < db->types.size() && Expand(this, &entry, params.detailedName, params.levels)) out.result = std::move(entry); + } else { + QueryFile* file; + if (!FindFileOrFail(db, project, request->id, + params.textDocument.uri.GetPath(), &file)) + return; + WorkingFile* working_file = + working_files->GetFileByFilename(file->def->path); + for (SymbolRef sym : + FindSymbolsAtLocation(working_file, file, params.position)) { + switch (sym.kind) { + case SymbolKind::Func: + out.result = BuildInitial(QueryFuncId(sym.id), params.detailedName, + params.levels); + break; + case SymbolKind::Type: + out.result = BuildInitial(QueryTypeId(sym.id), params.detailedName, + params.levels); + break; + case SymbolKind::Var: { + const QueryVar::Def* def = db->GetVar(sym).AnyDef(); + if (def && def->type) + out.result = BuildInitial(QueryTypeId(*def->type), params.detailedName, + params.levels); + break; + } + default: + continue; + } + break; + } } - QueueManager::WriteStdout(IpcId::CqueryMemberHierarchyExpand, out); + QueueManager::WriteStdout(IpcId::CqueryMemberHierarchy, out); } }; -REGISTER_MESSAGE_HANDLER(CqueryMemberHierarchyExpandHandler); +REGISTER_MESSAGE_HANDLER(CqueryMemberHierarchyHandler); + } // namespace