[clang-tools-extra] [clangd] Support callHierarchy/outgoingCalls (PR #91191)

2024-05-06 Thread Christian Kandeler via cfe-commits

ckandeler wrote:

> If I'm understanding correctly, the implementation approach in this PR only 
> finds callees in the current translation 
> unit.
> The approach in #77556 uses the project's index to find callees across 
> translation unit boundaries.

Right, that's obviously nicer.

> Regarding reviews: yes, it seems quite unfortunate that the original 
> developers seem to have largely moved on to 
> other things. I will do my best to make some progress of the project's review 
> backlog (including in particular 
> #86629 and #67802) as time permits.

Your work is highly appreciated, but I don't think it's reasonable to expect a 
single unpaid contributor to maintain the entire project, as appears to be the 
case right now.



https://github.com/llvm/llvm-project/pull/91191
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Support callHierarchy/outgoingCalls (PR #91191)

2024-05-06 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

If I'm understanding correctly, the implementation approach in this PR only 
finds callees in the current translation unit.

The approach in #77556 uses the project's index to find callees across 
translation unit boundaries.

Regarding reviews: yes, it seems quite unfortunate that the original developers 
seem to have largely moved on to other things. I will do my best to make some 
progress of the project's review backlog (including in particular 
https://github.com/llvm/llvm-project/pull/86629 and 
https://github.com/llvm/llvm-project/pull/67802) as time permits.

https://github.com/llvm/llvm-project/pull/91191
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Support callHierarchy/outgoingCalls (PR #91191)

2024-05-06 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> Seems nothing gets reviewed anymore these days.

Yeah, and unfortunately folks who are qualified/versed in clangd indices don't 
have enough bandwidths recently, nor does the author @HighCommander4.

https://github.com/llvm/llvm-project/pull/91191
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Support callHierarchy/outgoingCalls (PR #91191)

2024-05-06 Thread Christian Kandeler via cfe-commits

ckandeler wrote:

> I remembered @HighCommander4 had filed a similar PR at #77556. Is this one 
> separate, or are they actually the same (i.e. both are salvaged from 
> https://reviews.llvm.org/D93829)?

I didn't know about that one. Seems nothing gets reviewed anymore these days.

https://github.com/llvm/llvm-project/pull/91191
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Support callHierarchy/outgoingCalls (PR #91191)

2024-05-06 Thread Christian Kandeler via cfe-commits

https://github.com/ckandeler closed 
https://github.com/llvm/llvm-project/pull/91191
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Support callHierarchy/outgoingCalls (PR #91191)

2024-05-06 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

I remembered @HighCommander4 had filed a similar PR at 
https://github.com/llvm/llvm-project/pull/77556. Is this one separate, or are 
they actually the same (i.e. both are salvaged from 
https://reviews.llvm.org/D93829)?

https://github.com/llvm/llvm-project/pull/91191
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Support callHierarchy/outgoingCalls (PR #91191)

2024-05-06 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clangd

Author: Christian Kandeler (ckandeler)


Changes



---

Patch is 23.27 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/91191.diff


7 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 (+13) 
- (modified) clang-tools-extra/clangd/ClangdServer.h (+4) 
- (modified) clang-tools-extra/clangd/XRefs.cpp (+71) 
- (modified) clang-tools-extra/clangd/XRefs.h (+3) 
- (modified) clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp 
(+192-34) 


``diff
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 7fd599d4e1a0b0..5820a644088e3e 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1368,6 +1368,12 @@ void ClangdLSPServer::onCallHierarchyIncomingCalls(
   Server->incomingCalls(Params.item, std::move(Reply));
 }
 
+void ClangdLSPServer::onCallHierarchyOutgoingCalls(
+const CallHierarchyOutgoingCallsParams &Params,
+Callback> Reply) {
+  Server->outgoingCalls(Params.item, std::move(Reply));
+}
+
 void ClangdLSPServer::onClangdInlayHints(const InlayHintsParams &Params,
  Callback Reply) {
   // Our extension has a different representation on the wire than the 
standard.
@@ -1688,6 +1694,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 8bcb29522509b7..4981027372cb57 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 1c4c2a79b5c051..19d01dfbd873e2 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -898,6 +898,19 @@ void ClangdServer::incomingCalls(
  });
 }
 
+void ClangdServer::outgoingCalls(
+const CallHierarchyItem &Item,
+Callback> CB) {
+  auto Action = [Item,
+ CB = std::move(CB)](Expected InpAST) mutable {
+if (!InpAST)
+  return CB(InpAST.takeError());
+CB(clangd::outgoingCalls(InpAST->AST, Item));
+  };
+  WorkScheduler->runWithAST("Outgoing Calls", Item.uri.file(),
+std::move(Action));
+}
+
 void ClangdServer::inlayHints(PathRef File, std::optional RestrictRange,
   Callback> CB) {
   auto Action = [RestrictRange(std::move(RestrictRange)),
diff --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index 1661028be88b4e..4caef917c1ec16 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -288,6 +288,10 @@ class ClangdServer {
   void incomingCalls(const CallHierarchyItem &Item,
  Callback>);
 
+  /// Resolve outgoing calls for a given call hierarchy item.
+  void outgoingCalls(const CallHierarchyItem &Item,
+ Callback>);
+
   /// Resolve inlay hints for a given document.
   void inlayHints(PathRef File, std::optional RestrictRange,
   Callback>);
diff --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index cd909266489a85..b9bf944a7bba98 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -42,6 +42,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/Type.h"
+#include "clang/Analysis/CallGraph.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
@@

[clang-tools-extra] [clangd] Support callHierarchy/outgoingCalls (PR #91191)

2024-05-06 Thread Christian Kandeler via cfe-commits

https://github.com/ckandeler created 
https://github.com/llvm/llvm-project/pull/91191

None

>From d7cfeb6599fd507eed8935e452efd782fc3f0481 Mon Sep 17 00:00:00 2001
From: Christian Kandeler 
Date: Tue, 30 Apr 2024 18:20:05 +0200
Subject: [PATCH] [clangd] Support callHierarchy/outgoingCalls

---
 clang-tools-extra/clangd/ClangdLSPServer.cpp  |   7 +
 clang-tools-extra/clangd/ClangdLSPServer.h|   3 +
 clang-tools-extra/clangd/ClangdServer.cpp |  13 +
 clang-tools-extra/clangd/ClangdServer.h   |   4 +
 clang-tools-extra/clangd/XRefs.cpp|  71 ++
 clang-tools-extra/clangd/XRefs.h  |   3 +
 .../clangd/unittests/CallHierarchyTests.cpp   | 226 +++---
 7 files changed, 293 insertions(+), 34 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 7fd599d4e1a0b0..5820a644088e3e 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1368,6 +1368,12 @@ void ClangdLSPServer::onCallHierarchyIncomingCalls(
   Server->incomingCalls(Params.item, std::move(Reply));
 }
 
+void ClangdLSPServer::onCallHierarchyOutgoingCalls(
+const CallHierarchyOutgoingCallsParams &Params,
+Callback> Reply) {
+  Server->outgoingCalls(Params.item, std::move(Reply));
+}
+
 void ClangdLSPServer::onClangdInlayHints(const InlayHintsParams &Params,
  Callback Reply) {
   // Our extension has a different representation on the wire than the 
standard.
@@ -1688,6 +1694,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 8bcb29522509b7..4981027372cb57 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 1c4c2a79b5c051..19d01dfbd873e2 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -898,6 +898,19 @@ void ClangdServer::incomingCalls(
  });
 }
 
+void ClangdServer::outgoingCalls(
+const CallHierarchyItem &Item,
+Callback> CB) {
+  auto Action = [Item,
+ CB = std::move(CB)](Expected InpAST) mutable {
+if (!InpAST)
+  return CB(InpAST.takeError());
+CB(clangd::outgoingCalls(InpAST->AST, Item));
+  };
+  WorkScheduler->runWithAST("Outgoing Calls", Item.uri.file(),
+std::move(Action));
+}
+
 void ClangdServer::inlayHints(PathRef File, std::optional RestrictRange,
   Callback> CB) {
   auto Action = [RestrictRange(std::move(RestrictRange)),
diff --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index 1661028be88b4e..4caef917c1ec16 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -288,6 +288,10 @@ class ClangdServer {
   void incomingCalls(const CallHierarchyItem &Item,
  Callback>);
 
+  /// Resolve outgoing calls for a given call hierarchy item.
+  void outgoingCalls(const CallHierarchyItem &Item,
+ Callback>);
+
   /// Resolve inlay hints for a given document.
   void inlayHints(PathRef File, std::optional RestrictRange,
   Callback>);
diff --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index cd909266489a85..b9bf944a7bba98 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -42,6 +42,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/Type.h"
+#include "clang/Analysis/CallGraph.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/