From 5f18c81f3aa2de2cc536a5f0a262afc2efc67130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr> Date: Wed, 18 Mar 2020 11:01:48 +0100 Subject: [PATCH] [ivette] AST selection --- ivette/src/frama-c/states.js | 2 +- ivette/src/renderer/ASTview.js | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ivette/src/frama-c/states.js b/ivette/src/frama-c/states.js index 334a49f065f..7f1d3f78d05 100644 --- a/ivette/src/frama-c/states.js +++ b/ivette/src/frama-c/states.js @@ -434,7 +434,7 @@ const SELECTION = 'kernel.selection' ; setStateDefault( SELECTION , {} ); /** - @sumamry Current selection state. + @summary Current selection state. @return {array} `[selection,update]` for the current selection @description The selection is an object with many independant fields. diff --git a/ivette/src/renderer/ASTview.js b/ivette/src/renderer/ASTview.js index 0085ebf7cbf..e220194a0f3 100644 --- a/ivette/src/renderer/ASTview.js +++ b/ivette/src/renderer/ASTview.js @@ -43,26 +43,35 @@ const ASTview = () => { const buffer = React.useMemo( () => new Buffer(), []); const [ select, setSelect ] = States.useSelection(); const theFunction = select && select.function ; + const theMarker = select && select.marker ; + + // Hook: async loading React.useEffect( () => { buffer.clear(); if (theFunction) { - buffer.log('Loading',theFunction,'…'); + buffer.log('// Loading',theFunction,'…'); Server .sendGET("kernel.ast.printFunction", theFunction) .then(data => { buffer.clear(); + if (!data) + buffer.log('// No code for function ', theFunction); return print(buffer,data); }); } }, [ theFunction ] ); + // Callbacks + const onSelection = marker => setSelect({ marker }); + + // Component return ( <Vfill> - <div>Function: {select && select.function}</div> - <div>Marker: {select && select.marker}</div> <Text buffer={buffer} mode='text/x-csrc' theme='ambiance' + selection={theMarker} + onSelection={onSelection} readOnly /> </Vfill> ); -- GitLab