From caddc18860bfd33488afeeb7934d92bd13574691 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 23 Aug 2018 20:33:58 -0700 Subject: [PATCH] Uniquify $ccls/inheritanceHierarchy and add flat to $ccls/memberHierarchy --- src/messages/ccls_inheritanceHierarchy.cc | 3 +++ src/messages/ccls_memberHierarchy.cc | 31 ++++++++++++++++++++--- src/messages/initialize.cc | 13 ++++++---- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/messages/ccls_inheritanceHierarchy.cc b/src/messages/ccls_inheritanceHierarchy.cc index c169ab8f..bea19515 100644 --- a/src/messages/ccls_inheritanceHierarchy.cc +++ b/src/messages/ccls_inheritanceHierarchy.cc @@ -199,6 +199,9 @@ struct Handler_CclsInheritanceHierarchy for (auto &entry1 : entry->children) q.push(&entry1); } + std::sort(out1.result.begin(), out1.result.end()); + out1.result.erase(std::unique(out1.result.begin(), out1.result.end()), + out1.result.end()); } pipeline::WriteStdout(kMethodType, out1); } diff --git a/src/messages/ccls_memberHierarchy.cc b/src/messages/ccls_memberHierarchy.cc index 863678a6..7de03d9e 100644 --- a/src/messages/ccls_memberHierarchy.cc +++ b/src/messages/ccls_memberHierarchy.cc @@ -21,6 +21,7 @@ using namespace ccls; #include using namespace clang; +#include #include namespace { @@ -41,12 +42,12 @@ struct In_CclsMemberHierarchy : public RequestInMessage { bool qualified = false; int levels = 1; - }; - Params params; + bool flat = false; + } params; }; MAKE_REFLECT_STRUCT(In_CclsMemberHierarchy::Params, textDocument, position, id, - qualified, levels); + qualified, levels, flat); MAKE_REFLECT_STRUCT(In_CclsMemberHierarchy, id, params); REGISTER_IN_MESSAGE(In_CclsMemberHierarchy); @@ -276,7 +277,29 @@ struct Handler_CclsMemberHierarchy } } - pipeline::WriteStdout(kMethodType, out); + if (!params.flat) { + pipeline::WriteStdout(kMethodType, out); + return; + } + Out_LocationList out1; + out1.id = request->id; + if (out.result) { + std::queue q; + for (auto &entry1 : out.result->children) + q.push(&entry1); + while (q.size()) { + auto *entry = q.front(); + q.pop(); + if (entry->location.uri.raw_uri.size()) + out1.result.push_back({entry->location}); + for (auto &entry1 : entry->children) + q.push(&entry1); + } + std::sort(out1.result.begin(), out1.result.end()); + out1.result.erase(std::unique(out1.result.begin(), out1.result.end()), + out1.result.end()); + } + pipeline::WriteStdout(kMethodType, out1); } }; REGISTER_MESSAGE_HANDLER(Handler_CclsMemberHierarchy); diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 09f23529..b687b6a9 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -154,6 +154,8 @@ struct lsServerCapabilities { bool definitionProvider = true; // The server provides Goto Type Definition support. bool typeDefinitionProvider = true; + // The server provides Goto Implementation support. + bool implementationProvider = true; // The server provides find references support. bool referencesProvider = true; // The server provides document highlight support. @@ -182,11 +184,12 @@ struct lsServerCapabilities { }; MAKE_REFLECT_STRUCT(lsServerCapabilities, textDocumentSync, hoverProvider, completionProvider, signatureHelpProvider, - definitionProvider, typeDefinitionProvider, - referencesProvider, documentHighlightProvider, - documentSymbolProvider, workspaceSymbolProvider, - codeActionProvider, codeLensProvider, - documentFormattingProvider, documentRangeFormattingProvider, + definitionProvider, implementationProvider, + typeDefinitionProvider, referencesProvider, + documentHighlightProvider, documentSymbolProvider, + workspaceSymbolProvider, codeActionProvider, + codeLensProvider, documentFormattingProvider, + documentRangeFormattingProvider, documentOnTypeFormattingProvider, renameProvider, documentLinkProvider, executeCommandProvider);