Merge $cquery/*Hierarchy{Initial,Expand}

This commit is contained in:
Fangrui Song 2018-02-27 21:56:40 -08:00
parent 214eded2cb
commit ba87714e92
6 changed files with 130 additions and 210 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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.

View File

@ -12,12 +12,17 @@ bool operator&(CallType lhs, CallType rhs) {
return uint8_t(lhs) & uint8_t(rhs);
}
struct Ipc_CqueryCallHierarchyInitial
: public RequestMessage<Ipc_CqueryCallHierarchyInitial> {
const static IpcId kIpcId = IpcId::CqueryCallHierarchyInitial;
struct Ipc_CqueryCallHierarchy
: public RequestMessage<Ipc_CqueryCallHierarchy> {
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<QueryFuncId> 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<Ipc_CqueryCallHierarchyExpand> {
const static IpcId kIpcId = IpcId::CqueryCallHierarchyExpand;
struct Params {
Maybe<QueryFuncId> 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<Out_CqueryCallHierarchy> {
struct Entry {
@ -167,8 +152,8 @@ bool Expand(MessageHandler* m,
return true;
}
struct CqueryCallHierarchyInitialHandler
: BaseMessageHandler<Ipc_CqueryCallHierarchyInitial> {
struct CqueryCallHierarchyHandler
: BaseMessageHandler<Ipc_CqueryCallHierarchy> {
optional<Out_CqueryCallHierarchy::Entry> 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<Ipc_CqueryCallHierarchyExpand> {
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

View File

@ -3,12 +3,18 @@
#include "queue_manager.h"
namespace {
struct Ipc_CqueryInheritanceHierarchyInitial
: public RequestMessage<Ipc_CqueryInheritanceHierarchyInitial> {
const static IpcId kIpcId = IpcId::CqueryInheritanceHierarchyInitial;
struct Ipc_CqueryInheritanceHierarchy
: public RequestMessage<Ipc_CqueryInheritanceHierarchy> {
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<void>> 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<Ipc_CqueryInheritanceHierarchyExpand> {
const static IpcId kIpcId = IpcId::CqueryInheritanceHierarchyExpand;
struct Params {
Maybe<Id<void>> 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<Out_CqueryInheritanceHierarchy> {
@ -140,8 +127,8 @@ bool Expand(MessageHandler* m,
m->db->types[entry->id.id]);
}
struct CqueryInheritanceHierarchyInitialHandler
: BaseMessageHandler<Ipc_CqueryInheritanceHierarchyInitial> {
struct CqueryInheritanceHierarchyHandler
: BaseMessageHandler<Ipc_CqueryInheritanceHierarchy> {
optional<Out_CqueryInheritanceHierarchy::Entry>
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<Ipc_CqueryInheritanceHierarchyExpand> {
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

View File

@ -3,39 +3,31 @@
#include "queue_manager.h"
namespace {
struct Ipc_CqueryMemberHierarchyInitial
: public RequestMessage<Ipc_CqueryMemberHierarchyInitial> {
const static IpcId kIpcId = IpcId::CqueryMemberHierarchyInitial;
struct Ipc_CqueryMemberHierarchy
: public RequestMessage<Ipc_CqueryMemberHierarchy> {
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<QueryTypeId> 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<Ipc_CqueryMemberHierarchyExpand> {
const static IpcId kIpcId = IpcId::CqueryMemberHierarchyExpand;
struct Params {
Maybe<QueryTypeId> 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<Out_CqueryMemberHierarchy> {
@ -166,8 +158,8 @@ bool Expand(MessageHandler* m,
return true;
}
struct CqueryMemberHierarchyInitialHandler
: BaseMessageHandler<Ipc_CqueryMemberHierarchyInitial> {
struct CqueryMemberHierarchyHandler
: BaseMessageHandler<Ipc_CqueryMemberHierarchy> {
optional<Out_CqueryMemberHierarchy::Entry> 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<Ipc_CqueryMemberHierarchyExpand> {
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