2018-01-18 07:14:29 +00:00
|
|
|
#include "message_handler.h"
|
|
|
|
#include "query_utils.h"
|
|
|
|
#include "queue_manager.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct Ipc_CqueryMemberHierarchyInitial
|
2018-01-19 09:01:56 +00:00
|
|
|
: public RequestMessage<Ipc_CqueryMemberHierarchyInitial> {
|
2018-01-18 07:14:29 +00:00
|
|
|
const static IpcId kIpcId = IpcId::CqueryMemberHierarchyInitial;
|
|
|
|
lsTextDocumentPositionParams params;
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyInitial, id, params);
|
|
|
|
REGISTER_IPC_MESSAGE(Ipc_CqueryMemberHierarchyInitial);
|
|
|
|
|
|
|
|
struct Ipc_CqueryMemberHierarchyExpand
|
2018-01-19 09:01:56 +00:00
|
|
|
: public RequestMessage<Ipc_CqueryMemberHierarchyExpand> {
|
2018-01-18 07:14:29 +00:00
|
|
|
const static IpcId kIpcId = IpcId::CqueryMemberHierarchyExpand;
|
|
|
|
struct Params {
|
2018-02-11 21:42:48 +00:00
|
|
|
Maybe<QueryTypeId> type_id;
|
2018-01-18 08:09:13 +00:00
|
|
|
};
|
|
|
|
Params params;
|
2018-01-18 07:14:29 +00:00
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyExpand::Params, type_id);
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyExpand, id, params);
|
|
|
|
REGISTER_IPC_MESSAGE(Ipc_CqueryMemberHierarchyExpand);
|
|
|
|
|
|
|
|
struct Out_CqueryMemberHierarchy
|
|
|
|
: public lsOutMessage<Out_CqueryMemberHierarchy> {
|
|
|
|
struct Entry {
|
2018-01-31 08:35:04 +00:00
|
|
|
std::string_view name;
|
2018-02-11 18:25:37 +00:00
|
|
|
QueryTypeId type_id;
|
2018-01-18 07:14:29 +00:00
|
|
|
lsLocation location;
|
|
|
|
};
|
|
|
|
lsRequestId id;
|
|
|
|
std::vector<Entry> result;
|
|
|
|
};
|
2018-01-30 00:27:43 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy::Entry, name, type_id, location);
|
2018-01-18 07:14:29 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy, jsonrpc, id, result);
|
|
|
|
|
2018-01-30 00:27:43 +00:00
|
|
|
std::vector<Out_CqueryMemberHierarchy::Entry>
|
|
|
|
BuildInitial(QueryDatabase* db, WorkingFiles* working_files, QueryTypeId root) {
|
2018-01-18 07:14:29 +00:00
|
|
|
QueryType& root_type = db->types[root.id];
|
2018-02-11 04:01:10 +00:00
|
|
|
if (!root_type.def || !root_type.def->spell)
|
2018-01-18 07:14:29 +00:00
|
|
|
return {};
|
|
|
|
optional<lsLocation> def_loc =
|
2018-02-11 04:01:10 +00:00
|
|
|
GetLsLocation(db, working_files, *root_type.def->spell);
|
2018-01-18 07:14:29 +00:00
|
|
|
if (!def_loc)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
Out_CqueryMemberHierarchy::Entry entry;
|
2018-02-11 18:25:37 +00:00
|
|
|
entry.type_id = root;
|
2018-02-04 00:20:14 +00:00
|
|
|
entry.name = root_type.def->ShortName();
|
2018-01-18 07:14:29 +00:00
|
|
|
entry.location = *def_loc;
|
|
|
|
return {entry};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Out_CqueryMemberHierarchy::Entry>
|
2018-01-30 00:27:43 +00:00
|
|
|
ExpandNode(QueryDatabase* db, WorkingFiles* working_files, QueryTypeId root) {
|
2018-01-18 07:14:29 +00:00
|
|
|
QueryType& root_type = db->types[root.id];
|
2018-02-18 05:52:14 +00:00
|
|
|
const QueryType::Def* def = root_type.AnyDef();
|
|
|
|
if (!def)
|
2018-01-18 07:14:29 +00:00
|
|
|
return {};
|
|
|
|
|
|
|
|
std::vector<Out_CqueryMemberHierarchy::Entry> ret;
|
2018-02-18 05:52:14 +00:00
|
|
|
EachWithGen(db->vars, def->vars, [&](QueryVar& var) {
|
|
|
|
const QueryVar::Def* def1 = var.AnyDef();
|
2018-01-18 07:14:29 +00:00
|
|
|
Out_CqueryMemberHierarchy::Entry entry;
|
2018-02-18 05:52:14 +00:00
|
|
|
entry.name = def1->ShortName();
|
|
|
|
entry.type_id = def1->type ? *def1->type : QueryTypeId();
|
|
|
|
if (def->spell) {
|
2018-01-18 07:14:29 +00:00
|
|
|
optional<lsLocation> loc =
|
2018-02-18 05:52:14 +00:00
|
|
|
GetLsLocation(db, working_files, *def1->spell);
|
2018-01-18 07:14:29 +00:00
|
|
|
// TODO invalid location
|
|
|
|
if (loc)
|
|
|
|
entry.location = *loc;
|
|
|
|
}
|
|
|
|
ret.push_back(std::move(entry));
|
2018-02-04 00:20:14 +00:00
|
|
|
});
|
2018-01-18 07:14:29 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct CqueryMemberHierarchyInitialHandler
|
|
|
|
: BaseMessageHandler<Ipc_CqueryMemberHierarchyInitial> {
|
|
|
|
void Run(Ipc_CqueryMemberHierarchyInitial* request) override {
|
|
|
|
QueryFile* file;
|
|
|
|
if (!FindFileOrFail(db, project, request->id,
|
|
|
|
request->params.textDocument.uri.GetPath(), &file))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WorkingFile* working_file =
|
|
|
|
working_files->GetFileByFilename(file->def->path);
|
|
|
|
Out_CqueryMemberHierarchy out;
|
|
|
|
out.id = request->id;
|
|
|
|
|
2018-02-09 17:42:10 +00:00
|
|
|
for (const SymbolRef& sym :
|
2018-01-30 00:27:43 +00:00
|
|
|
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
2018-02-09 17:42:10 +00:00
|
|
|
if (sym.kind == SymbolKind::Type) {
|
2018-02-11 18:25:37 +00:00
|
|
|
out.result = BuildInitial(db, working_files, QueryTypeId(sym.id));
|
2018-01-18 07:14:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-02-09 17:42:10 +00:00
|
|
|
if (sym.kind == SymbolKind::Var) {
|
2018-02-18 05:52:14 +00:00
|
|
|
const QueryVar::Def* def = db->GetVar(sym).AnyDef();
|
|
|
|
if (def && def->type)
|
|
|
|
out.result = BuildInitial(db, working_files, *def->type);
|
2018-01-18 07:14:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QueueManager::WriteStdout(IpcId::CqueryMemberHierarchyInitial, out);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
REGISTER_MESSAGE_HANDLER(CqueryMemberHierarchyInitialHandler);
|
|
|
|
|
|
|
|
struct CqueryMemberHierarchyExpandHandler
|
|
|
|
: BaseMessageHandler<Ipc_CqueryMemberHierarchyExpand> {
|
|
|
|
void Run(Ipc_CqueryMemberHierarchyExpand* request) override {
|
|
|
|
Out_CqueryMemberHierarchy out;
|
|
|
|
out.id = request->id;
|
|
|
|
// |ExpandNode| uses -1 to indicate invalid |type_id|.
|
2018-02-11 21:56:34 +00:00
|
|
|
if (request->params.type_id)
|
2018-02-11 21:42:48 +00:00
|
|
|
out.result = ExpandNode(db, working_files, *request->params.type_id);
|
2018-01-18 07:14:29 +00:00
|
|
|
|
|
|
|
QueueManager::WriteStdout(IpcId::CqueryMemberHierarchyExpand, out);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
REGISTER_MESSAGE_HANDLER(CqueryMemberHierarchyExpandHandler);
|
|
|
|
} // namespace
|