From 52af885d84cfd66b5da0557a52a134ed087b4b2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20B=C3=BChler?= <david.buhler@cea.fr>
Date: Wed, 24 Jun 2020 09:48:23 +0200
Subject: [PATCH] [ivette] ASTview: adds contextual menu "go to callers" on
 functions declaration.

Uses the Eva request "eva.callers".
---
 ivette/src/renderer/ASTview.tsx | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/ivette/src/renderer/ASTview.tsx b/ivette/src/renderer/ASTview.tsx
index d786d7cf038..5f170ce0da1 100644
--- a/ivette/src/renderer/ASTview.tsx
+++ b/ivette/src/renderer/ASTview.tsx
@@ -64,6 +64,21 @@ async function loadAST(
   }
 }
 
+async function callers(updateSelection: any, kf: string) {
+  try {
+    const data = await Server.GET({
+      endpoint: 'eva.callers',
+      params: kf,
+    });
+    const locations = data.map((d: string[2]) => (
+      { function: d[0], marker: d[1] }
+    ));
+    updateSelection({ locations });
+  } catch (err) {
+    PP.error('Fail to retrieve callers of function', kf, err);
+  }
+}
+
 // --------------------------------------------------------------------------
 // --- AST Printer
 // --------------------------------------------------------------------------
@@ -107,17 +122,27 @@ const ASTview = () => {
   }
 
   function onContextMenu(id: string) {
+    const items = [];
     const marker = markers[id];
-    if (marker && marker.kind === 'function') {
-      const item = {
+    if (marker?.kind === 'lvalue' && marker?.var === 'function') {
+      items.push({
         label: `Go to definition of ${marker.name}`,
         onClick: () => {
           const location = { function: marker.name };
           updateSelection({ location });
         },
-      };
-      Dome.popupMenu([item]);
+      });
+    }
+    if (marker?.kind === 'declaration'
+        && marker?.var === 'function'
+        && marker?.name) {
+      items.push({
+        label: 'Go to callers',
+        onClick: () => callers(updateSelection, marker.name),
+      });
     }
+    if (items.length > 0)
+      Dome.popupMenu(items);
   }
 
   // Theme Popup
-- 
GitLab