From 04609a503b2c2301ac87cf25adc97ae7ab9ced6b Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Fri, 27 Jul 2018 07:00:00 -0700 Subject: [PATCH] Remove cquery_member_hierarchy --- CMakeLists.txt | 5 +- README.md | 2 +- src/messages/cquery_member_hierarchy.cc | 261 ------------------------ 3 files changed, 3 insertions(+), 265 deletions(-) delete mode 100644 src/messages/cquery_member_hierarchy.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ecc285aa..00303480d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ option(SYSTEM_CLANG "Use system installation of Clang instead of \ downloading Clang" OFF) option(ASAN "Compile with address sanitizers" OFF) option(ASSERTS "Compile with asserts enabled" OFF) -option(CI "Add -Werror or equivalent" OFF) +option(CI "Add -Werror or equivalent" OFF) # Sources for the executable are specified at end of CMakeLists.txt add_executable(cquery "") @@ -52,7 +52,7 @@ if(MSVC) /wd4800 /wd4068 # Disable unknown pragma warning $<$:/FS> - $<$:/WX> + $<$:/WX> ) else() # Common GCC/Clang(Linux) options @@ -325,7 +325,6 @@ target_sources(cquery PRIVATE src/messages/cquery_freshen_index.cc src/messages/cquery_index_file.cc src/messages/cquery_inheritance_hierarchy.cc - src/messages/cquery_member_hierarchy.cc src/messages/cquery_vars.cc src/messages/cquery_wait.cc src/messages/exit.cc diff --git a/README.md b/README.md index 5a0668147..765d5f531 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ some extra features to boot: * code completion (with both signature help and snippets) * finding [definition](src/messages/text_document_definition.cc)/[references](src/messages/text_document_references.cc) - * [call (caller/callee) hierarchy](src/messages/cquery_call_hierarchy.cc), [inheritance (base/derived) hierarchy](src/messages/cquery_inheritance_hierarchy.cc), [member hierarchy](src/messages/cquery_member_hierarchy.cc) + * [call (caller/callee) hierarchy](src/messages/cquery_call_hierarchy.cc), [inheritance (base/derived) hierarchy](src/messages/cquery_inheritance_hierarchy.cc) * [symbol rename](src/messages/text_document_rename.cc) * [document symbols](src/messages/text_document_document_symbol.cc) and approximate search of [workspace symbol](src/messages/workspace_symbol.cc) * [hover information](src/messages/text_document_hover.cc) diff --git a/src/messages/cquery_member_hierarchy.cc b/src/messages/cquery_member_hierarchy.cc deleted file mode 100644 index 4af6e0b92..000000000 --- a/src/messages/cquery_member_hierarchy.cc +++ /dev/null @@ -1,261 +0,0 @@ -#include "message_handler.h" -#include "query_utils.h" -#include "queue_manager.h" - -namespace { -MethodType kMethodType = "$cquery/memberHierarchy"; - -struct In_CqueryMemberHierarchy : public RequestInMessage { - MethodType GetMethodType() const override { return kMethodType; } - - 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(In_CqueryMemberHierarchy::Params, - textDocument, - position, - id, - detailedName, - levels); -MAKE_REFLECT_STRUCT(In_CqueryMemberHierarchy, id, params); -REGISTER_IN_MESSAGE(In_CqueryMemberHierarchy); - -struct Out_CqueryMemberHierarchy - : public lsOutMessage { - struct Entry { - QueryId::Type id; - std::string name; - std::string fieldName; - lsLocation location; - // For unexpanded nodes, this is an upper bound because some entities may be - // undefined. If it is 0, there are no members. - int numChildren = 0; - // Empty if the |levels| limit is reached. - std::vector children; - }; - lsRequestId id; - optional result; -}; -MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy::Entry, - id, - name, - fieldName, - location, - numChildren, - children); -MAKE_REFLECT_STRUCT_OPTIONALS_MANDATORY(Out_CqueryMemberHierarchy, - jsonrpc, - id, - result); - -bool Expand(MessageHandler* m, - Out_CqueryMemberHierarchy::Entry* entry, - bool detailed_name, - int levels); - -// Add a field to |entry| which is a Func/Type. -void DoField(MessageHandler* m, - Out_CqueryMemberHierarchy::Entry* entry, - const QueryVar& var, - bool detailed_name, - int levels) { - const QueryVar::Def* def1 = var.AnyDef(); - if (!def1) - return; - Out_CqueryMemberHierarchy::Entry entry1; - if (detailed_name) - entry1.fieldName = def1->DetailedName(false); - else - entry1.fieldName = std::string(def1->ShortName()); - if (def1->spell) { - if (optional loc = - GetLsLocation(m->db, m->working_files, *def1->spell)) - entry1.location = *loc; - } - if (def1->type) { - entry1.id = *def1->type; - if (Expand(m, &entry1, detailed_name, levels)) - entry->children.push_back(std::move(entry1)); - } else { - entry1.id = QueryId::Type(); - entry->children.push_back(std::move(entry1)); - } -} - -// Expand a type node by adding members recursively to it. -bool Expand(MessageHandler* m, - Out_CqueryMemberHierarchy::Entry* entry, - bool detailed_name, - int levels) { - const QueryType& type = m->db->types[entry->id.id]; - const QueryType::Def* def = type.AnyDef(); - // builtin types have no declaration and empty |detailed_name|. - if (CXType_FirstBuiltin <= type.usr && type.usr <= CXType_LastBuiltin) { - entry->name = ClangBuiltinTypeName(CXTypeKind(type.usr)); - return true; - } - if (!def) - return false; - if (detailed_name) - entry->name = def->detailed_name; - else - entry->name = std::string(def->ShortName()); - std::unordered_set seen; - if (levels > 0) { - std::vector stack; - seen.insert(type.usr); - stack.push_back(&type); - while (stack.size()) { - const auto* def = stack.back()->AnyDef(); - stack.pop_back(); - if (def) { - EachDefinedType(m->db, def->bases, [&](QueryType& type1) { - if (!seen.count(type1.usr)) { - seen.insert(type1.usr); - stack.push_back(&type1); - } - }); - if (def->alias_of) { - const QueryType::Def* def1 = m->db->types[def->alias_of->id].AnyDef(); - Out_CqueryMemberHierarchy::Entry entry1; - entry1.id = *def->alias_of; - if (def1 && def1->spell) { - // The declaration of target type. - if (optional loc = - GetLsLocation(m->db, m->working_files, *def1->spell)) - entry1.location = *loc; - } else if (def->spell) { - // Builtin types have no declaration but the typedef declaration - // itself is useful. - if (optional loc = - GetLsLocation(m->db, m->working_files, *def->spell)) - entry1.location = *loc; - } - if (def1 && detailed_name) - entry1.fieldName = def1->detailed_name; - if (Expand(m, &entry1, detailed_name, levels - 1)) { - // For builtin types |name| is set. - if (detailed_name && entry1.fieldName.empty()) - entry1.fieldName = std::string(entry1.name); - entry->children.push_back(std::move(entry1)); - } - } else { - EachDefinedVar(m->db, def->vars, [&](QueryVar& var) { - DoField(m, entry, var, detailed_name, levels - 1); - }); - } - } - } - entry->numChildren = int(entry->children.size()); - } else - entry->numChildren = def->alias_of ? 1 : int(def->vars.size()); - return true; -} - -struct Handler_CqueryMemberHierarchy - : BaseMessageHandler { - MethodType GetMethodType() const override { return kMethodType; } - - optional BuildInitial(QueryId::Func root_id, - bool detailed_name, - int levels) { - const auto* def = db->GetFunc(root_id).AnyDef(); - if (!def) - return {}; - - Out_CqueryMemberHierarchy::Entry entry; - // Not type, |id| is invalid. - if (detailed_name) - entry.name = std::string(def->DetailedName(false)); - else - entry.name = std::string(def->ShortName()); - if (def->spell) { - if (optional loc = - GetLsLocation(db, working_files, *def->spell)) - entry.location = *loc; - } - EachDefinedVar(db, def->vars, [&](QueryVar& var) { - DoField(this, &entry, var, detailed_name, levels - 1); - }); - return entry; - } - - optional BuildInitial(QueryId::Type root_id, - bool detailed_name, - int levels) { - const auto* def = db->types[root_id.id].AnyDef(); - if (!def) - return {}; - - Out_CqueryMemberHierarchy::Entry entry; - entry.id = root_id; - if (def->spell) { - if (optional loc = - GetLsLocation(db, working_files, *def->spell)) - entry.location = *loc; - } - Expand(this, &entry, detailed_name, levels); - return entry; - } - - void Run(In_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; - // entry.name is empty as it is known by the client. - 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.GetAbsolutePath(), &file)) - return; - WorkingFile* working_file = - working_files->GetFileByFilename(file->def->path); - for (QueryId::SymbolRef sym : - FindSymbolsAtLocation(working_file, file, params.position)) { - switch (sym.kind) { - case SymbolKind::Func: - out.result = BuildInitial(QueryId::Func(sym.id), - params.detailedName, params.levels); - break; - case SymbolKind::Type: - out.result = BuildInitial(QueryId::Type(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(QueryId::Type(*def->type), - params.detailedName, params.levels); - break; - } - default: - continue; - } - break; - } - } - - QueueManager::WriteStdout(kMethodType, out); - } -}; -REGISTER_MESSAGE_HANDLER(Handler_CqueryMemberHierarchy); - -} // namespace