[clang-tools-extra] lsOutgoing calls (PR #77556)
https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/77556 None >From 42d64ab78fe1c001e766fe2b94de167ae7bc6ddf Mon Sep 17 00:00:00 2001 From: Quentin Chateau Date: Mon, 18 Sep 2023 03:01:03 -0400 Subject: [PATCH 1/4] [clangd] Support outgoing calls in call hierarchy The implementation is very close the the incoming calls implementation. The results of the outgoing calls are expected to be the exact symmetry of the incoming calls. Differential Revision: https://reviews.llvm.org/D93829 --- clang-tools-extra/clangd/ClangdLSPServer.cpp | 7 + clang-tools-extra/clangd/ClangdLSPServer.h| 3 + clang-tools-extra/clangd/ClangdServer.cpp | 9 + clang-tools-extra/clangd/ClangdServer.h | 4 + clang-tools-extra/clangd/XRefs.cpp| 63 clang-tools-extra/clangd/XRefs.h | 3 + clang-tools-extra/clangd/index/Index.cpp | 5 + clang-tools-extra/clangd/index/Index.h| 22 ++ clang-tools-extra/clangd/index/MemIndex.cpp | 19 ++ clang-tools-extra/clangd/index/MemIndex.h | 4 + clang-tools-extra/clangd/index/Merge.cpp | 34 +++ clang-tools-extra/clangd/index/Merge.h| 3 + .../clangd/index/ProjectAware.cpp | 13 + clang-tools-extra/clangd/index/dex/Dex.cpp| 25 ++ clang-tools-extra/clangd/index/dex/Dex.h | 18 ++ .../clangd/test/type-hierarchy-ext.test | 2 + .../clangd/test/type-hierarchy.test | 51 +--- .../clangd/unittests/CallHierarchyTests.cpp | 271 +- .../clangd/unittests/CodeCompleteTests.cpp| 6 + .../clangd/unittests/RenameTests.cpp | 12 + 20 files changed, 454 insertions(+), 120 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index a87da252b7a7e9..482dae521fbcd5 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -1373,6 +1373,12 @@ void ClangdLSPServer::onInlayHint(const InlayHintsParams &Params, std::move(Reply)); } +void ClangdLSPServer::onCallHierarchyOutgoingCalls( +const CallHierarchyOutgoingCallsParams &Params, +Callback> Reply) { + Server->outgoingCalls(Params.item, std::move(Reply)); +} + void ClangdLSPServer::applyConfiguration( const ConfigurationSettings &Settings) { // Per-file update to the compilation database. @@ -1654,6 +1660,7 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind, Bind.method("typeHierarchy/subtypes", this, &ClangdLSPServer::onSubTypes); Bind.method("textDocument/prepareCallHierarchy", this, &ClangdLSPServer::onPrepareCallHierarchy); Bind.method("callHierarchy/incomingCalls", this, &ClangdLSPServer::onCallHierarchyIncomingCalls); + Bind.method("callHierarchy/outgoingCalls", this, &ClangdLSPServer::onCallHierarchyOutgoingCalls); Bind.method("textDocument/selectionRange", this, &ClangdLSPServer::onSelectionRange); Bind.method("textDocument/documentLink", this, &ClangdLSPServer::onDocumentLink); Bind.method("textDocument/semanticTokens/full", this, &ClangdLSPServer::onSemanticTokens); diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h index 79579c22b788a9..50a0a7e43a4436 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.h +++ b/clang-tools-extra/clangd/ClangdLSPServer.h @@ -153,6 +153,9 @@ class ClangdLSPServer : private ClangdServer::Callbacks, void onCallHierarchyIncomingCalls( const CallHierarchyIncomingCallsParams &, Callback>); + void onCallHierarchyOutgoingCalls( + const CallHierarchyOutgoingCallsParams &, + Callback>); void onClangdInlayHints(const InlayHintsParams &, Callback); void onInlayHint(const InlayHintsParams &, Callback>); diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 6fb2641e8793db..5c0303c9bf9448 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -880,6 +880,15 @@ void ClangdServer::inlayHints(PathRef File, std::optional RestrictRange, WorkScheduler->runWithAST("InlayHints", File, std::move(Action), Transient); } +void ClangdServer::outgoingCalls( +const CallHierarchyItem &Item, +Callback> CB) { + WorkScheduler->run("Outgoing Calls", "", + [CB = std::move(CB), Item, this]() mutable { + CB(clangd::outgoingCalls(Item, Index)); + }); +} + void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) { // FIXME: Do nothing for now. This will be used for indexing and potentially // invalidating other caches. diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h index a416602251428b..3319c44e75d3fc 100644 --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/ClangdServer.h @@ -288,6 +28
[clang-tools-extra] lsOutgoing calls (PR #77556)
llvmbot wrote: @llvm/pr-subscribers-clangd Author: Nathan Ridge (HighCommander4) Changes --- Patch is 49.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/77556.diff 23 Files Affected: - (modified) clang-tools-extra/clangd/ClangdLSPServer.cpp (+7) - (modified) clang-tools-extra/clangd/ClangdLSPServer.h (+3) - (modified) clang-tools-extra/clangd/ClangdServer.cpp (+9) - (modified) clang-tools-extra/clangd/ClangdServer.h (+4) - (modified) clang-tools-extra/clangd/XRefs.cpp (+59) - (modified) clang-tools-extra/clangd/XRefs.h (+3) - (modified) clang-tools-extra/clangd/index/Index.cpp (+5) - (modified) clang-tools-extra/clangd/index/Index.h (+35) - (modified) clang-tools-extra/clangd/index/MemIndex.cpp (+20) - (modified) clang-tools-extra/clangd/index/MemIndex.h (+4) - (modified) clang-tools-extra/clangd/index/Merge.cpp (+34) - (modified) clang-tools-extra/clangd/index/Merge.h (+3) - (modified) clang-tools-extra/clangd/index/ProjectAware.cpp (+13) - (modified) clang-tools-extra/clangd/index/Ref.h (+3) - (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+17-3) - (modified) clang-tools-extra/clangd/index/SymbolCollector.h (+1) - (modified) clang-tools-extra/clangd/index/dex/Dex.cpp (+42) - (modified) clang-tools-extra/clangd/index/dex/Dex.h (+20) - (modified) clang-tools-extra/clangd/test/type-hierarchy-ext.test (+2) - (modified) clang-tools-extra/clangd/test/type-hierarchy.test (+1-50) - (modified) clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp (+201-70) - (modified) clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp (+6) - (modified) clang-tools-extra/clangd/unittests/RenameTests.cpp (+12) ``diff diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index a87da252b7a7e9..482dae521fbcd5 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -1373,6 +1373,12 @@ void ClangdLSPServer::onInlayHint(const InlayHintsParams &Params, std::move(Reply)); } +void ClangdLSPServer::onCallHierarchyOutgoingCalls( +const CallHierarchyOutgoingCallsParams &Params, +Callback> Reply) { + Server->outgoingCalls(Params.item, std::move(Reply)); +} + void ClangdLSPServer::applyConfiguration( const ConfigurationSettings &Settings) { // Per-file update to the compilation database. @@ -1654,6 +1660,7 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind, Bind.method("typeHierarchy/subtypes", this, &ClangdLSPServer::onSubTypes); Bind.method("textDocument/prepareCallHierarchy", this, &ClangdLSPServer::onPrepareCallHierarchy); Bind.method("callHierarchy/incomingCalls", this, &ClangdLSPServer::onCallHierarchyIncomingCalls); + Bind.method("callHierarchy/outgoingCalls", this, &ClangdLSPServer::onCallHierarchyOutgoingCalls); Bind.method("textDocument/selectionRange", this, &ClangdLSPServer::onSelectionRange); Bind.method("textDocument/documentLink", this, &ClangdLSPServer::onDocumentLink); Bind.method("textDocument/semanticTokens/full", this, &ClangdLSPServer::onSemanticTokens); diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h index 79579c22b788a9..50a0a7e43a4436 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.h +++ b/clang-tools-extra/clangd/ClangdLSPServer.h @@ -153,6 +153,9 @@ class ClangdLSPServer : private ClangdServer::Callbacks, void onCallHierarchyIncomingCalls( const CallHierarchyIncomingCallsParams &, Callback>); + void onCallHierarchyOutgoingCalls( + const CallHierarchyOutgoingCallsParams &, + Callback>); void onClangdInlayHints(const InlayHintsParams &, Callback); void onInlayHint(const InlayHintsParams &, Callback>); diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 6fb2641e8793db..5c0303c9bf9448 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -880,6 +880,15 @@ void ClangdServer::inlayHints(PathRef File, std::optional RestrictRange, WorkScheduler->runWithAST("InlayHints", File, std::move(Action), Transient); } +void ClangdServer::outgoingCalls( +const CallHierarchyItem &Item, +Callback> CB) { + WorkScheduler->run("Outgoing Calls", "", + [CB = std::move(CB), Item, this]() mutable { + CB(clangd::outgoingCalls(Item, Index)); + }); +} + void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) { // FIXME: Do nothing for now. This will be used for indexing and potentially // invalidating other caches. diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h index a416602251428b..3319c44e75d3fc 100644 --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/Cl
[clang-tools-extra] lsOutgoing calls (PR #77556)
HighCommander4 wrote: (Not sure what happened here, the PR was somehow created while I was still writing the description. Anyways, updating the title now.) https://github.com/llvm/llvm-project/pull/77556 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits