Skip to content
Snippets Groups Projects
Commit 6f8c8671 authored by David Bühler's avatar David Bühler
Browse files

[ivette] Automatically selects the 'main' function.

- when the AST is recomputed;
- when the current project changes and the selection is empty.
parent dbd6cf01
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,11 @@ const compute_internal: Server.ExecRequest<null,null> = {
/** Ensures that AST is computed */
export const compute: Server.ExecRequest<null,null>= compute_internal;
/** Emitted when the AST has been computed */
export const computed: Server.Signal = {
name: 'kernel.ast.computed',
};
/** Marker kind */
export enum markerKind {
/** Expression */
......
......@@ -201,14 +201,20 @@ export default function ASTview() {
return () => { buffer.off('change', setBullets); };
}, [buffer, setBullets]);
async function reload() {
printed.current = theFunction;
loadAST(buffer, theFunction, theMarker);
}
// Hook: async loading
React.useEffect(() => {
if (printed.current !== theFunction) {
printed.current = theFunction;
loadAST(buffer, theFunction, theMarker);
}
if (printed.current !== theFunction)
reload();
});
// Also reload the buffer when the AST is recomputed.
Server.onSignal(Ast.computed, reload);
React.useEffect(() => {
const decorator = (marker: string) => {
if (multipleSelections?.some((location) => location?.marker === marker))
......
......@@ -28,7 +28,6 @@ import * as Dome from 'dome';
import * as Dialogs from 'dome/dialogs';
import * as Server from 'frama-c/server';
import * as Ast from 'frama-c/api/kernel/ast';
import * as States from 'frama-c/states';
const cFilter = {
name: 'C source files',
......@@ -46,8 +45,6 @@ async function setFiles(): Promise<void> {
});
await Server.send(Ast.setFiles, files);
await Server.send(Ast.compute, { });
const main = await Server.send(Ast.getMainFunction, { });
States.setSelection({ fct: main });
return;
}
......
......@@ -772,4 +772,21 @@ export function useSelection(): [Selection, (a: SelectionActions) => void] {
return [current, (action) => setCurrent(reducer(current, action))];
}
/* Select the main function when the AST is recomputed, or when the current
project changes and the selection is still empty. */
async function selectMainFunction() {
const main = await Server.send(Ast.getMainFunction, { });
const selection = {
...emptySelection,
current: { fct: main },
};
GlobalSelection.setValue(selection);
}
Server.onSignal(Ast.computed, selectMainFunction);
PROJECT.on(async () => {
const selection = GlobalSelection.getValue();
if (selection === emptySelection)
selectMainFunction();
});
// --------------------------------------------------------------------------
......@@ -37,6 +37,11 @@ let () = Request.register ~package
~descr:(Md.plain "Ensures that AST is computed")
~input:(module Junit) ~output:(module Junit) Ast.compute
let computed_signal = Request.signal ~package ~name:"computed"
~descr:(Md.plain "Emitted when the AST has been computed")
let () = Ast.apply_after_computed (fun _ -> Request.emit computed_signal)
let ast_update_hook f =
Ast.add_hook_on_update f;
Ast.apply_after_computed (fun _ -> f ())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment