Add detailed_name to hierarchies

This commit is contained in:
Fangrui Song 2018-02-25 15:24:51 -08:00
parent f84cb1c85f
commit 968c15a2ca
2 changed files with 69 additions and 20 deletions

View File

@ -12,6 +12,7 @@ struct Ipc_CqueryCallHierarchyInitial
lsTextDocumentIdentifier textDocument; lsTextDocumentIdentifier textDocument;
lsPosition position; lsPosition position;
bool callee = false; bool callee = false;
bool detailedName = false;
int levels = 1; int levels = 1;
}; };
Params params; Params params;
@ -20,6 +21,7 @@ MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyInitial::Params,
textDocument, textDocument,
position, position,
callee, callee,
detailedName,
levels); levels);
MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyInitial, id, params); MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyInitial, id, params);
REGISTER_IPC_MESSAGE(Ipc_CqueryCallHierarchyInitial); REGISTER_IPC_MESSAGE(Ipc_CqueryCallHierarchyInitial);
@ -34,11 +36,16 @@ struct Ipc_CqueryCallHierarchyExpand
Maybe<QueryFuncId> id; Maybe<QueryFuncId> id;
// true: callee tree; false: caller tree // true: callee tree; false: caller tree
bool callee = false; bool callee = false;
bool detailedName = false;
int levels = 1; int levels = 1;
}; };
Params params; Params params;
}; };
MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyExpand::Params, id, callee, levels); MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyExpand::Params,
id,
callee,
detailedName,
levels);
MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyExpand, id, params); MAKE_REFLECT_STRUCT(Ipc_CqueryCallHierarchyExpand, id, params);
REGISTER_IPC_MESSAGE(Ipc_CqueryCallHierarchyExpand); REGISTER_IPC_MESSAGE(Ipc_CqueryCallHierarchyExpand);
@ -68,6 +75,7 @@ MAKE_REFLECT_STRUCT(Out_CqueryCallHierarchy, jsonrpc, id, result);
void Expand(MessageHandler* m, void Expand(MessageHandler* m,
Out_CqueryCallHierarchy::Entry* entry, Out_CqueryCallHierarchy::Entry* entry,
bool callee, bool callee,
bool detailed_name,
int levels) { int levels) {
const QueryFunc& func = m->db->funcs[entry->id.id]; const QueryFunc& func = m->db->funcs[entry->id.id];
const QueryFunc::Def* def = func.AnyDef(); const QueryFunc::Def* def = func.AnyDef();
@ -90,10 +98,13 @@ void Expand(MessageHandler* m,
if (levels > 0) { if (levels > 0) {
Out_CqueryCallHierarchy::Entry entry1; Out_CqueryCallHierarchy::Entry entry1;
entry1.id = QueryFuncId(use.id); entry1.id = QueryFuncId(use.id);
if (detailed_name)
entry1.name = rel_def->detailed_name;
else
entry1.name = rel_def->ShortName(); entry1.name = rel_def->ShortName();
entry1.location = *loc; entry1.location = *loc;
entry1.callType = call_type; entry1.callType = call_type;
Expand(m, &entry1, callee, levels - 1); Expand(m, &entry1, callee, detailed_name, levels - 1);
entry->children.push_back(std::move(entry1)); entry->children.push_back(std::move(entry1));
} }
} }
@ -150,6 +161,7 @@ struct CqueryCallHierarchyInitialHandler
: BaseMessageHandler<Ipc_CqueryCallHierarchyInitial> { : BaseMessageHandler<Ipc_CqueryCallHierarchyInitial> {
optional<Out_CqueryCallHierarchy::Entry> BuildInitial(QueryFuncId root_id, optional<Out_CqueryCallHierarchy::Entry> BuildInitial(QueryFuncId root_id,
bool callee, bool callee,
bool detailed_name,
int levels) { int levels) {
const auto* def = db->funcs[root_id.id].AnyDef(); const auto* def = db->funcs[root_id.id].AnyDef();
if (!def) if (!def)
@ -158,7 +170,7 @@ struct CqueryCallHierarchyInitialHandler
Out_CqueryCallHierarchy::Entry entry; Out_CqueryCallHierarchy::Entry entry;
entry.id = root_id; entry.id = root_id;
entry.name = def->ShortName(); entry.name = def->ShortName();
Expand(this, &entry, callee, levels); Expand(this, &entry, callee, detailed_name, levels);
return entry; return entry;
} }
@ -177,8 +189,8 @@ struct CqueryCallHierarchyInitialHandler
for (SymbolRef sym : for (SymbolRef sym :
FindSymbolsAtLocation(working_file, file, params.position)) { FindSymbolsAtLocation(working_file, file, params.position)) {
if (sym.kind == SymbolKind::Func) { if (sym.kind == SymbolKind::Func) {
out.result = out.result = BuildInitial(QueryFuncId(sym.id), params.callee,
BuildInitial(QueryFuncId(sym.id), params.callee, params.levels); params.detailedName, params.levels);
break; break;
} }
} }
@ -199,7 +211,8 @@ struct CqueryCallHierarchyExpandHandler
entry.id = *params.id; entry.id = *params.id;
// entry.name is empty and it is known by the client. // entry.name is empty and it is known by the client.
if (entry.id.id < db->funcs.size()) if (entry.id.id < db->funcs.size())
Expand(this, &entry, params.callee, params.levels); Expand(this, &entry, params.callee, params.detailedName,
params.levels);
out.result = std::move(entry); out.result = std::move(entry);
} }

View File

@ -9,6 +9,7 @@ struct Ipc_CqueryMemberHierarchyInitial
struct Params { struct Params {
lsTextDocumentIdentifier textDocument; lsTextDocumentIdentifier textDocument;
lsPosition position; lsPosition position;
bool detailedName = false;
int levels = 1; int levels = 1;
}; };
Params params; Params params;
@ -17,6 +18,7 @@ struct Ipc_CqueryMemberHierarchyInitial
MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyInitial::Params, MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyInitial::Params,
textDocument, textDocument,
position, position,
detailedName,
levels); levels);
MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyInitial, id, params); MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyInitial, id, params);
REGISTER_IPC_MESSAGE(Ipc_CqueryMemberHierarchyInitial); REGISTER_IPC_MESSAGE(Ipc_CqueryMemberHierarchyInitial);
@ -26,11 +28,12 @@ struct Ipc_CqueryMemberHierarchyExpand
const static IpcId kIpcId = IpcId::CqueryMemberHierarchyExpand; const static IpcId kIpcId = IpcId::CqueryMemberHierarchyExpand;
struct Params { struct Params {
Maybe<QueryTypeId> id; Maybe<QueryTypeId> id;
bool detailedName = false;
int levels = 1; int levels = 1;
}; };
Params params; Params params;
}; };
MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyExpand::Params, id, levels); MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyExpand::Params, id, detailedName, levels);
MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyExpand, id, params); MAKE_REFLECT_STRUCT(Ipc_CqueryMemberHierarchyExpand, id, params);
REGISTER_IPC_MESSAGE(Ipc_CqueryMemberHierarchyExpand); REGISTER_IPC_MESSAGE(Ipc_CqueryMemberHierarchyExpand);
@ -59,13 +62,41 @@ MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy::Entry,
children); children);
MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy, jsonrpc, id, result); MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy, jsonrpc, id, result);
void Expand(MessageHandler* m, Out_CqueryMemberHierarchy::Entry* entry, int levels) { void Expand(MessageHandler* m,
const QueryType::Def* def = m->db->types[entry->id.id].AnyDef(); Out_CqueryMemberHierarchy::Entry* entry,
bool detailed_name,
int levels) {
const QueryType& type = m->db->types[entry->id.id];
const QueryType::Def* def = type.AnyDef();
if (!def) { if (!def) {
entry->numChildren = 0; entry->numChildren = 0;
return; return;
} }
if (CXType_FirstBuiltin <= type.usr && type.usr <= CXType_LastBuiltin) {
switch (type.usr) {
// clang-format off
case CXType_Bool: entry->name = "bool"; break;
case CXType_Char_U: entry->name = "char"; break;
case CXType_UChar: entry->name = "unsigned char"; break;
case CXType_Int: entry->name = "int"; break;
case CXType_UInt: entry->name = "unsigned int"; break;
case CXType_ULong: entry->name = "unsigned long"; break;
case CXType_ULongLong: entry->name = "unsigned long long"; break;
case CXType_Char_S: entry->name = "char"; break;
case CXType_SChar: entry->name = "signed char"; break;
case CXType_Long: entry->name = "long"; break;
case CXType_LongLong: entry->name = "long long"; break;
case CXType_Float: entry->name = "float"; break;
case CXType_Double: entry->name = "double"; break;
case CXType_LongDouble: entry->name = "long double"; break;
// clang-format on
}
} else {
if (detailed_name)
entry->name = def->detailed_name;
else
entry->name = def->ShortName(); entry->name = def->ShortName();
}
if (def->spell) { if (def->spell) {
if (optional<lsLocation> loc = if (optional<lsLocation> loc =
GetLsLocation(m->db, m->working_files, *def->spell)) GetLsLocation(m->db, m->working_files, *def->spell))
@ -78,7 +109,7 @@ void Expand(MessageHandler* m, Out_CqueryMemberHierarchy::Entry* entry, int leve
Out_CqueryMemberHierarchy::Entry entry1; Out_CqueryMemberHierarchy::Entry entry1;
entry1.id = def1->type ? *def1->type : QueryTypeId(); entry1.id = def1->type ? *def1->type : QueryTypeId();
entry1.field_name = def1->ShortName(); entry1.field_name = def1->ShortName();
Expand(m, &entry1, levels - 1); Expand(m, &entry1, detailed_name, levels - 1);
entry->children.push_back(std::move(entry1)); entry->children.push_back(std::move(entry1));
}); });
entry->numChildren = int(entry->children.size()); entry->numChildren = int(entry->children.size());
@ -88,6 +119,7 @@ void Expand(MessageHandler* m, Out_CqueryMemberHierarchy::Entry* entry, int leve
struct CqueryMemberHierarchyInitialHandler struct CqueryMemberHierarchyInitialHandler
: BaseMessageHandler<Ipc_CqueryMemberHierarchyInitial> { : BaseMessageHandler<Ipc_CqueryMemberHierarchyInitial> {
optional<Out_CqueryMemberHierarchy::Entry> BuildInitial(QueryTypeId root_id, optional<Out_CqueryMemberHierarchy::Entry> BuildInitial(QueryTypeId root_id,
bool detailed_name,
int levels) { int levels) {
const auto* def = db->types[root_id.id].AnyDef(); const auto* def = db->types[root_id.id].AnyDef();
if (!def) if (!def)
@ -95,14 +127,15 @@ struct CqueryMemberHierarchyInitialHandler
Out_CqueryMemberHierarchy::Entry entry; Out_CqueryMemberHierarchy::Entry entry;
entry.id = root_id; entry.id = root_id;
Expand(this, &entry, levels); Expand(this, &entry, detailed_name, levels);
return entry; return entry;
} }
void Run(Ipc_CqueryMemberHierarchyInitial* request) override { void Run(Ipc_CqueryMemberHierarchyInitial* request) override {
QueryFile* file; QueryFile* file;
const auto& params = request->params;
if (!FindFileOrFail(db, project, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) params.textDocument.uri.GetPath(), &file))
return; return;
WorkingFile* working_file = WorkingFile* working_file =
@ -110,16 +143,18 @@ struct CqueryMemberHierarchyInitialHandler
Out_CqueryMemberHierarchy out; Out_CqueryMemberHierarchy out;
out.id = request->id; out.id = request->id;
for (const SymbolRef& sym : for (SymbolRef sym :
FindSymbolsAtLocation(working_file, file, request->params.position)) { FindSymbolsAtLocation(working_file, file, params.position)) {
if (sym.kind == SymbolKind::Type) { if (sym.kind == SymbolKind::Type) {
out.result = BuildInitial(QueryTypeId(sym.id), request->params.levels); out.result = BuildInitial(QueryTypeId(sym.id), params.detailedName,
params.levels);
break; break;
} }
if (sym.kind == SymbolKind::Var) { if (sym.kind == SymbolKind::Var) {
const QueryVar::Def* def = db->GetVar(sym).AnyDef(); const QueryVar::Def* def = db->GetVar(sym).AnyDef();
if (def && def->type) if (def && def->type)
out.result = BuildInitial(QueryTypeId(*def->type), request->params.levels); out.result = BuildInitial(QueryTypeId(*def->type),
params.detailedName, params.levels);
break; break;
} }
} }
@ -132,14 +167,15 @@ REGISTER_MESSAGE_HANDLER(CqueryMemberHierarchyInitialHandler);
struct CqueryMemberHierarchyExpandHandler struct CqueryMemberHierarchyExpandHandler
: BaseMessageHandler<Ipc_CqueryMemberHierarchyExpand> { : BaseMessageHandler<Ipc_CqueryMemberHierarchyExpand> {
void Run(Ipc_CqueryMemberHierarchyExpand* request) override { void Run(Ipc_CqueryMemberHierarchyExpand* request) override {
const auto& params = request->params;
Out_CqueryMemberHierarchy out; Out_CqueryMemberHierarchy out;
out.id = request->id; out.id = request->id;
if (request->params.id) { if (params.id) {
Out_CqueryMemberHierarchy::Entry entry; Out_CqueryMemberHierarchy::Entry entry;
entry.id = *request->params.id; entry.id = *request->params.id;
// entry.name is empty and it is known by the client. // entry.name is empty and it is known by the client.
if (entry.id.id < db->types.size()) if (entry.id.id < db->types.size())
Expand(this, &entry, request->params.levels); Expand(this, &entry, params.detailedName, params.levels);
out.result = std::move(entry); out.result = std::move(entry);
} }