why3ide.ml 34.7 KB
Newer Older
1

Sylvain Dailler's avatar
Sylvain Dailler committed
2
(*
3 4 5
open Format
open Why3
open Gconfig
6 7 8
open Stdlib
open Session_itp
open Controller_itp
9 10
open Session_user_interface
open Historic
Sylvain Dailler's avatar
Sylvain Dailler committed
11 12 13 14 15 16 17
*)

open Why3
open Itp_server
open Gconfig
open Session_user_interface.Historic
open Stdlib
18

19 20
external reset_gc : unit -> unit = "ml_reset_gc"

21 22
let debug = Debug.lookup_flag "ide_info"

Sylvain Dailler's avatar
Sylvain Dailler committed
23
module Server = Make (Protocol.Protocol_why3ide)
24

Sylvain Dailler's avatar
Sylvain Dailler committed
25
module type Protocol = sig
26

Sylvain Dailler's avatar
Sylvain Dailler committed
27 28 29 30 31 32 33 34 35 36 37 38 39
  val send_request: ide_request -> unit
  val get_notified: unit -> notification list

end

module Make (P: Protocol) = struct

(* TODO add at end *)
(*  let treat_notifications () = ?????
  let treat_user_inputs () = ?????

  let _ = Unix_Scheduler.idle ~prio:1 treat_notifications
  let _ = Unix_Scheduler.idle ~prio:1 treat_user_interface
40
*)
Sylvain Dailler's avatar
Sylvain Dailler committed
41
(* TODO adapt the rest *)
42

Sylvain Dailler's avatar
Sylvain Dailler committed
43 44 45 46 47 48
(* Global initialization has not yet been done *)
let is_init = ref false
(* Initial config is empty *)
(* TODO *)
let gconfig = Gconfig.default_config
let main_dir = ref ""
49

Sylvain Dailler's avatar
Sylvain Dailler committed
50 51 52 53 54
(* TODO temp globals *)
let provers_list = ref []
let transformation_list = ref []
let strategy_list = ref []
let commands : string list ref = ref []
55

Sylvain Dailler's avatar
Sylvain Dailler committed
56 57 58 59 60 61 62 63 64 65 66
(* -------------- Library -------------------- *)

(* TODO
let _ =
  let treat_user_inputs () =
  (* Before accepting user inputs, open a file *)
  (* TODO right now the server initialize by default
     P.send_requests (Init usage_str spec)*)
    let l = P.get_notified () in
    treat_requests init l
*)
67

Sylvain Dailler's avatar
Sylvain Dailler committed
68
(*
69 70 71 72 73 74
let task_driver =
  let main = Whyconf.get_main gconfig.config in
  let d = Filename.concat (Whyconf.datadir main)
                          (Filename.concat "drivers" "why3_itp.drv")
  in
  Driver.load_driver gconfig.env d []
Sylvain Dailler's avatar
Sylvain Dailler committed
75
*)
76

Sylvain Dailler's avatar
Sylvain Dailler committed
77
(*
MARCHE Claude's avatar
MARCHE Claude committed
78 79 80 81
let provers : Whyconf.config_prover Whyconf.Mprover.t =
  Whyconf.get_provers gconfig.config

let cont =
MARCHE Claude's avatar
MARCHE Claude committed
82 83 84 85 86
  try
    Session_user_interface.cont_from_files spec usage_str gconfig.env files provers
  with e ->
       eprintf "%a@." Exn_printer.exn_printer e;
       exit 1
Sylvain Dailler's avatar
Sylvain Dailler committed
87
*)
88

MARCHE Claude's avatar
MARCHE Claude committed
89

MARCHE Claude's avatar
MARCHE Claude committed
90 91 92 93 94
(********************************)
(* Source language highlighting *)
(********************************)

let (why_lang, any_lang) =
Sylvain Dailler's avatar
Sylvain Dailler committed
95 96
(*  let main = Whyconf.get_main gconfig.config in*)
  let load_path = Filename.concat !main_dir "lang" in
MARCHE Claude's avatar
MARCHE Claude committed
97 98 99 100 101 102 103 104
  let languages_manager =
    GSourceView2.source_language_manager ~default:true
  in
  languages_manager#set_search_path
    (load_path :: languages_manager#search_path);
  let why_lang =
    match languages_manager#language "why3" with
    | None ->
Sylvain Dailler's avatar
Sylvain Dailler committed
105
        Format.eprintf "language file for 'why3' not found in directory %s@."
MARCHE Claude's avatar
MARCHE Claude committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
          load_path;
        exit 1
    | Some _ as l -> l in
  let any_lang filename =
    match languages_manager#guess_language ~filename () with
    | None -> why_lang
    | Some _ as l -> l in
  (why_lang, any_lang)

(* Borrowed from Frama-C src/gui/source_manager.ml:
Try to convert a source file either as UTF-8 or as locale. *)
let try_convert s =
  try
    if Glib.Utf8.validate s then s else Glib.Convert.locale_to_utf8 s
  with Glib.Convert.Error _ ->
    try
      Glib.Convert.convert_with_fallback
        ~fallback:"#neither UTF-8 nor locale nor ISO-8859-15#"
        ~to_codeset:"UTF-8"
        ~from_codeset:"ISO_8859-15"
        s
    with Glib.Convert.Error _ as e -> Printexc.to_string e



131 132 133
(**********************)
(* Graphical elements *)
(**********************)
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170

let main_window =
  let w = GWindow.window
            ~allow_grow:true ~allow_shrink:true
            ~width:gconfig.window_width
            ~height:gconfig.window_height
            ~title:"Why3 Interactive Proof Session" ()
  in
  (* callback to record the new size of the main window when changed, so
   that on restart the window size is the same as the last session *)
  let (_ : GtkSignal.id) =
    w#misc#connect#size_allocate
      ~callback:
      (fun {Gtk.width=w;Gtk.height=h} ->
       gconfig.window_height <- h;
       gconfig.window_width <- w)
  in w

(* the main window contains a vertical box, containing:
   1. the menu
   2. an horizontal box
 *)

let vbox = GPack.vbox ~packing:main_window#add ()

let menubar = GMenu.menu_bar
  ~packing:(vbox#pack ?from:None ?expand:None ?fill:None ?padding:None)
  ()

let hb = GPack.hbox ~packing:vbox#add ()

(* 1. Menu *)

let factory = new GMenu.factory menubar

let accel_group = factory#accel_group

MARCHE Claude's avatar
MARCHE Claude committed
171 172
(* 1.1 "File" menu *)

173 174 175 176 177 178 179 180 181
let file_menu = factory#add_submenu "_File"
let file_factory = new GMenu.factory file_menu ~accel_group

let exit_function ~destroy () =
  ignore(destroy); GMain.quit ()

let (_ : GtkSignal.id) = main_window#connect#destroy
  ~callback:(exit_function ~destroy:true)

182 183
let (_ : GMenu.menu_item) =
  file_factory#add_item ~key:GdkKeysyms._S "_Save session"
Sylvain Dailler's avatar
Sylvain Dailler committed
184
    ~callback:(fun () -> P.send_request (Save, ""))
185 186 187 188

let (replay_menu_item : GMenu.menu_item) =
  file_factory#add_item ~key:GdkKeysyms._R "_Replay all"

189 190
let (_ : GMenu.menu_item) =
  file_factory#add_item ~key:GdkKeysyms._Q "_Quit"
Sylvain Dailler's avatar
Sylvain Dailler committed
191
    ~callback:(fun x -> exit_function ~destroy:false x; P.send_request (Exit, ""))
192

MARCHE Claude's avatar
MARCHE Claude committed
193 194 195 196 197 198 199

(* 1.2 "View" menu

   the entries in that menu are defined later

*)

200 201 202 203
(* 2. horizontal box contains:
   2.1 TODO: a tool box ?
   2.2 a horizontal paned containing:
     2.2.1 a scrolled window to hold the tree view of the session
Clément Fumex's avatar
Clément Fumex committed
204
     2.2.2 a vertical paned containing
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
*)

let hp = GPack.paned `HORIZONTAL ~packing:hb#add ()

let scrollview =
  let sv =
    GBin.scrolled_window
      ~hpolicy:`AUTOMATIC ~vpolicy:`AUTOMATIC
      ~width:gconfig.tree_width ~shadow_type:`ETCHED_OUT
      ~packing:hp#add ()
  in
  let (_ : GtkSignal.id) =
    sv#misc#connect#size_allocate
      ~callback:
      (fun {Gtk.width=w;Gtk.height=_h} ->
       gconfig.tree_width <- w)
  in sv

Clément Fumex's avatar
Clément Fumex committed
223
let vpan222 = GPack.paned `VERTICAL ~packing:hp#add ()
224 225 226 227 228 229

(*  the scrolled window 2.2.1 contains a GTK tree

*)


MARCHE Claude's avatar
MARCHE Claude committed
230 231 232 233 234 235 236 237
(* view for the session tree *)
let scrolled_session_view =
  GBin.scrolled_window
    ~hpolicy: `AUTOMATIC ~vpolicy: `AUTOMATIC
    ~shadow_type:`ETCHED_OUT
    ~packing:scrollview#add
    ()

238 239 240
let cols = new GTree.column_list
let name_column = cols#add Gobject.Data.string
let index_column = cols#add Gobject.Data.int
241
let status_column = cols#add Gobject.Data.gobject
MARCHE Claude's avatar
MARCHE Claude committed
242

243 244 245 246
let name_renderer = GTree.cell_renderer_text [`XALIGN 0.]
let view_name_column = GTree.view_column ~title:"Theories/Goals" ()
let () =
  view_name_column#pack name_renderer;
247 248 249 250 251 252
  view_name_column#add_attribute name_renderer "text" name_column;
  view_name_column#set_sizing `AUTOSIZE

let status_renderer = GTree.cell_renderer_pixbuf [ ]
let view_status_column = GTree.view_column ~title:"Status"
    ~renderer:(status_renderer, ["pixbuf", status_column])()
253

254 255 256 257 258 259 260 261 262
let goals_model,goals_view =
  Debug.dprintf debug "[GUI] Creating tree model...@?";
  let model = GTree.tree_store cols in
  let view = GTree.view ~model ~packing:scrolled_session_view#add () in
(*
  let () = view#selection#set_mode (* `SINGLE *) `MULTIPLE in
  let () = view#set_rules_hint true in
 *)
  ignore (view#append_column view_name_column);
263
  ignore (view#append_column view_status_column);
264 265 266 267 268 269
(*
  ignore (view#append_column view_status_column);
  ignore (view#append_column view_time_column);
*)
  Debug.dprintf debug " done@.";
  model,view
270

Clément Fumex's avatar
Clément Fumex committed
271
(* vpan222 contains:
272
   2.2.2.1 a view of the current task
Clément Fumex's avatar
Clément Fumex committed
273 274
   2.2.2.2 a vertiacal pan which contains
     2.2.2.2.1 the input field to type commands
275
     2.2.2.2.2 a scrolled window to hold the output of the commands
276 277 278 279 280 281
 *)

let scrolled_task_view =
  GBin.scrolled_window
    ~hpolicy: `AUTOMATIC ~vpolicy: `AUTOMATIC
    ~shadow_type:`ETCHED_OUT
Clément Fumex's avatar
Clément Fumex committed
282
    ~packing:vpan222#add ()
283 284 285 286

let task_view =
  GSourceView2.source_view
    ~editable:false
Clément Fumex's avatar
Clément Fumex committed
287
    ~cursor_visible:false
288 289 290 291
    ~show_line_numbers:true
    ~packing:scrolled_task_view#add
    ()

Clément Fumex's avatar
Clément Fumex committed
292
let vbox2222 = GPack.vbox ~packing:vpan222#add  ()
293

294 295 296 297 298 299
let hbox22221 =
  GPack.hbox
    ~packing:(vbox2222#pack ?from:None ?expand:None ?fill:None ?padding:None) ()

let monitor =
  GMisc.label
MARCHE Claude's avatar
MARCHE Claude committed
300 301 302
    ~text:"  0/0/0"
    ~width:80
    ~xalign:0.0
303
    ~packing:(hbox22221#pack ?from:None ?expand:None ?fill:None ?padding:None) ()
304

MARCHE Claude's avatar
MARCHE Claude committed
305 306
let command_entry = GEdit.entry ~packing:hbox22221#add ()

MARCHE Claude's avatar
MARCHE Claude committed
307
let message_zone =
308 309 310 311
  let sv = GBin.scrolled_window
      ~hpolicy:`AUTOMATIC ~vpolicy:`AUTOMATIC
      ~shadow_type:`ETCHED_OUT ~packing:vbox2222#add ()
  in
MARCHE Claude's avatar
MARCHE Claude committed
312
  GText.view ~editable:false ~cursor_visible:false
313 314
    ~packing:sv#add ()

315
(**** Monitor *****)
Sylvain Dailler's avatar
Sylvain Dailler committed
316
(* TODO
317 318 319 320 321 322 323 324 325 326 327 328 329
let fan n =
  match n mod 4 with
    | 0 -> "|"
    | 1 | -3 -> "\\"
    | 2 | -2 -> "-"
    | 3 | -1 -> "/"
    | _ -> assert false

let update_monitor =
  let c = ref 0 in
  fun t s r ->
  reset_gc ();
  incr c;
MARCHE Claude's avatar
MARCHE Claude committed
330 331 332
  let f = if r=0 then "  " else fan (!c / 2) ^ " " in
  monitor#set_text
    (f ^ (string_of_int t) ^ "/" ^ (string_of_int s) ^ "/" ^ (string_of_int r))
Sylvain Dailler's avatar
Sylvain Dailler committed
333
*)
MARCHE Claude's avatar
MARCHE Claude committed
334

335 336 337 338 339 340
(****************************)
(* command entry completion *)
(****************************)

let completion_cols = new GTree.column_list
let completion_col = completion_cols#add Gobject.Data.string
341
(* let text_col = completion_cols#add Gobject.Data.string *)
342 343 344 345 346 347 348
let completion_model = GTree.tree_store completion_cols

let command_entry_completion : GEdit.entry_completion =
  GEdit.entry_completion ~model:completion_model ~minimum_key_length:1 ~entry:command_entry ()

let add_completion_entry s =
  let row = completion_model#append () in
349
  (* completion_model#set ~row ~column:text_col "test"; *)
350 351
  completion_model#set ~row ~column:completion_col s

352 353 354 355 356 357 358
let match_function s iter =
  let candidate = completion_model#get ~row:iter ~column:completion_col in
  try
    ignore (Str.search_forward (Str.regexp s) candidate 0);
    true
  with Not_found -> false

Sylvain Dailler's avatar
Sylvain Dailler committed
359
let init_comp () =
360
  (* add the names of all the the transformations *)
Sylvain Dailler's avatar
Sylvain Dailler committed
361
  List.iter add_completion_entry !transformation_list;
362
  (* add the name of the commands *)
Sylvain Dailler's avatar
Sylvain Dailler committed
363 364
(*  List.iter (fun (c,_,_) -> add_completion_entry c)
    !commands; (* TODO re-add commands *)*)
365 366
  (* todo: add queries *)

367
  (* add provers *)
Sylvain Dailler's avatar
Sylvain Dailler committed
368 369
  List.iter add_completion_entry !provers_list;
(*
370 371
  Whyconf.Hprover.iter
      (fun p _ -> add_completion_entry (p.Whyconf.prover_name^","^p.Whyconf.prover_version))
372
      cont.controller_provers;
Sylvain Dailler's avatar
Sylvain Dailler committed
373
*)
374 375 376
  add_completion_entry "auto";
  add_completion_entry "auto 2";

377
  command_entry_completion#set_text_column completion_col;
378 379 380 381 382 383 384
  command_entry_completion#set_match_func match_function;
(*  ignore (command_entry_completion#connect#match_selected
    ~callback:(fun _ iter ->
        command_entry#set_text "test";
        true));*)

    (* GTree.model_filter -> Gtk.tree_iter -> bool *)
385

386
  command_entry#set_completion command_entry_completion
387 388


MARCHE Claude's avatar
MARCHE Claude committed
389

Sylvain Dailler's avatar
Sylvain Dailler committed
390 391 392 393 394

(*********************)
(* Terminal historic *)
(*********************)

395
let list_commands = create_historic()
Sylvain Dailler's avatar
Sylvain Dailler committed
396 397 398

let _ =
  command_entry#event#connect#key_press
399 400 401
    ~callback:(fun (ev: 'a Gdk.event) ->
      match GdkEvent.Key.keyval ev with
      | k when k = GdkKeysyms._Up -> (* Arrow up *)
402 403 404 405 406
          let s = print_next_command list_commands in
          (match s with
          | None -> true
          | Some s ->
              (command_entry#set_text s; true))
407
      | k when k = GdkKeysyms._Down -> (* Arrow down *)
408 409 410 411 412
          let s = print_prev_command list_commands in
          (match s with
          | None -> true
          | Some s ->
              (command_entry#set_text s; true))
Sylvain Dailler's avatar
Sylvain Dailler committed
413 414 415
      | _ -> false
      )

416 417 418 419
(********************************************)
(* controller instance on the GTK scheduler *)
(********************************************)

Sylvain Dailler's avatar
Sylvain Dailler committed
420
(*
421 422 423 424 425 426 427 428 429 430
module S = struct
    let idle ~prio f =
      let (_ : GMain.Idle.id) = GMain.Idle.add ~prio f in ()

    let timeout ~ms f =
      let (_ : GMain.Timeout.id) = GMain.Timeout.add ~ms ~callback:f in
      ()
end

module C = Controller_itp.Make(S)
Sylvain Dailler's avatar
Sylvain Dailler committed
431
*)
432

433 434 435
let (_ : GtkSignal.id) =
  replay_menu_item#connect#activate
    ~callback:(fun () ->
Sylvain Dailler's avatar
Sylvain Dailler committed
436 437 438
               (*let callback = C.replay_print in*)
               P.send_request (Replay, ""))
(*C.replay ~use_steps:false cont ~callback ~remove_obsolete:false)*)
439

Sylvain Dailler's avatar
Sylvain Dailler committed
440
let tree = ref (Node ("", "", Root, {proved = false; name= ""}, []))
441 442 443 444

(***********************************)
(* Mapping session to the GTK tree *)
(***********************************)
Sylvain Dailler's avatar
Sylvain Dailler committed
445
(*
446 447
type index =
  | Inone
448
  | IproofAttempt of proofAttemptID
449
  | IproofNode of proofNodeID
450
  | Itransformation  of transID
451 452 453 454
  | Ifile of file
  | Itheory of theory

let model_index : index Hint.t = Stdlib.Hint.create 17
455 456 457 458
let get_index iter =
  let index = goals_model#get ~row:iter ~column:index_column in
  Hint.find model_index index

459 460 461 462 463 464 465 466 467 468 469 470 471
(* To each node we have the corresponding row_reference *)
let file_id_to_gtree : GTree.row_reference Hstr.t = Hstr.create 3
let th_id_to_gtree   : GTree.row_reference Ident.Hid.t = Ident.Hid.create 7
let pn_id_to_gtree   : GTree.row_reference Hpn.t = Hpn.create 17
let tn_id_to_gtree   : GTree.row_reference Htn.t = Htn.create 17
let pan_id_to_gtree  : GTree.row_reference Hpan.t = Hpan.create 17

(* TODO exception for those: *)
let row_from_file file = Hstr.find file_id_to_gtree (file.file_name)
let row_from_th   th   = Ident.Hid.find th_id_to_gtree (theory_name th)
let row_from_pn   pn   = Hpn.find pn_id_to_gtree pn
let row_from_tn   tn   = Htn.find tn_id_to_gtree tn
let row_from_pan  pan  = Hpan.find pan_id_to_gtree pan
Sylvain Dailler's avatar
Sylvain Dailler committed
472 473 474 475 476 477 478 479 480 481 482 483
*)

let model_node: node_ID Hint.t = Stdlib.Hint.create 17

let node_from_iter iter =
  let index = goals_model#get ~row:iter ~column:index_column in
  Hint.find model_node index

let iter_node: GTree.row_reference Hstr.t = Stdlib.Hstr.create 17

let row_ref_from_node node =
  Hstr.find iter_node node
484 485 486

let new_node =
  let cpt = ref (-1) in
Sylvain Dailler's avatar
Sylvain Dailler committed
487
  fun ?parent ?(collapse=false) name (ind: node_ID) ->
488
  incr cpt;
Sylvain Dailler's avatar
Sylvain Dailler committed
489
  Hint.add model_node !cpt ind;
490 491 492 493 494 495 496 497
  let parent = Opt.map (fun x -> x#iter) parent in
  let iter = goals_model#append ?parent () in
  goals_model#set ~row:iter ~column:name_column name;
  goals_model#set ~row:iter ~column:index_column !cpt;
  let new_ref = goals_model#get_row_reference (goals_model#get_path iter) in
  (* By default expand_path when creating a new node *)
  if not collapse then goals_view#expand_to_path (goals_model#get_path iter);
  begin
Sylvain Dailler's avatar
Sylvain Dailler committed
498 499
(* TODO reverse hashtable necessary ? *)
    (*
500 501 502 503 504 505 506 507 508 509 510 511
    match ind with
    | IproofAttempt panid ->
       Hpan.add pan_id_to_gtree panid new_ref
    | IproofNode pnid ->
      Hpn.add pn_id_to_gtree pnid new_ref
    | Itransformation tnid ->
      Htn.add tn_id_to_gtree tnid new_ref
    | Ifile file ->
      Hstr.add file_id_to_gtree file.file_name new_ref
    | Itheory th ->
      Ident.Hid.add th_id_to_gtree (theory_name th) new_ref
    | Inone -> ()
Sylvain Dailler's avatar
Sylvain Dailler committed
512
     *)
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
  end;
  new_ref


let image_of_result ~obsolete rOpt =
  match rOpt with
  | None -> !image_undone
  | Some r ->
    match r.Call_provers.pr_answer with
    | Call_provers.Valid ->
      if obsolete then !image_valid_obs else !image_valid
    | Call_provers.Invalid ->
      if obsolete then !image_invalid_obs else !image_invalid
    | Call_provers.Timeout ->
      if obsolete then !image_timeout_obs else !image_timeout
    | Call_provers.OutOfMemory ->
      if obsolete then !image_outofmemory_obs else !image_outofmemory
    | Call_provers.StepLimitExceeded ->
      if obsolete then !image_steplimitexceeded_obs
      else !image_steplimitexceeded
    | Call_provers.Unknown _ ->
      if obsolete then !image_unknown_obs else !image_unknown
    | Call_provers.Failure _ ->
      if obsolete then !image_failure_obs else !image_failure
    | Call_provers.HighFailure ->
      if obsolete then !image_failure_obs else !image_failure
539

Sylvain Dailler's avatar
Sylvain Dailler committed
540 541 542 543 544 545 546 547 548 549 550 551
let get_type_info (n: node_ID) (t: session_tree): node_type * node_info =
  (* TODO parcours du tree pour obtenir le type et l'info *)
  Obj.magic "TODO"

let set_status_column_from_cont iter =
  let node_ID = node_from_iter iter in
  let _, info = get_type_info node_ID !tree in
  let image =
    if info.proved then
      !image_valid
    else
      !image_unknown
552 553
  in
  goals_model#set ~row:iter ~column:status_column image
554

Sylvain Dailler's avatar
Sylvain Dailler committed
555
(*
556
let build_subtree_proof_attempt_from_goal cont row_ref id =
557 558
  Whyconf.Hprover.iter
    (fun pa panid ->
559 560 561 562
       let name = Pp.string_of Whyconf.print_prover pa in
       let r = new_node ~parent:row_ref name (IproofAttempt panid) in
       set_status_column_from_cont cont r#iter)
    (get_proof_attempt_ids cont.controller_session id)
563

564 565
let rec build_subtree_from_goal cont th_row_reference id =
  let ses = cont.controller_session in
566
  let name = get_proof_name ses id in
567
  let row_ref =
568 569
    new_node ~parent:th_row_reference name.Ident.id_string
             (IproofNode id)
MARCHE Claude's avatar
MARCHE Claude committed
570
  in
571
  set_status_column_from_cont cont row_ref#iter;
572 573
  List.iter
    (fun trans_id ->
574
      ignore (build_subtree_from_trans cont row_ref trans_id))
575
    (get_transformations ses id);
576
  build_subtree_proof_attempt_from_goal cont row_ref id
577

578 579
and build_subtree_from_trans cont goal_row_reference trans_id =
  let ses = cont.controller_session in
580 581 582
  let name = get_transf_name ses trans_id in
  let row_ref =
    new_node ~parent:goal_row_reference name (Itransformation trans_id) in
583
  set_status_column_from_cont cont row_ref#iter;
584 585
  List.iter
    (fun goal_id ->
586 587 588
      (build_subtree_from_goal cont row_ref goal_id))
    (get_sub_tasks ses trans_id);
  row_ref
Sylvain Dailler's avatar
Sylvain Dailler committed
589 590 591 592 593 594 595 596
*)

let rec build_tree_from_session ?parent (t: session_tree) =
  match t with
  | Node (node_ID, pos_ID, node_type, node_info, subtree_list) ->
    let row_ref = new_node ?parent:parent node_info.name node_ID in
    set_status_column_from_cont row_ref#iter;
    List.iter (build_tree_from_session ~parent:row_ref) subtree_list
597

Sylvain Dailler's avatar
Sylvain Dailler committed
598
(*
599 600
let build_tree_from_session cont =
  let ses = cont.controller_session in
601 602 603 604
  let files = get_files ses in
  Stdlib.Hstr.iter
    (fun _ file ->
       let file_row_reference = new_node file.file_name (Ifile file) in
605
       set_status_column_from_cont cont file_row_reference#iter;
606 607 608 609 610 611
       List.iter (fun th ->
                  let th_row_reference =
                    new_node ~parent:file_row_reference
                             (theory_name th).Ident.id_string
                             (Itheory th)
                  in
612 613
                  set_status_column_from_cont cont th_row_reference#iter;
                  List.iter (build_subtree_from_goal cont th_row_reference)
614 615 616
                            (theory_goals th))
                 file.file_theories)
    files
Sylvain Dailler's avatar
Sylvain Dailler committed
617
*)
618

619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
(*******************************)
(* commands of the "View" menu *)
(*******************************)

let view_menu = factory#add_submenu "_View"
let view_factory = new GMenu.factory view_menu ~accel_group

(* goals view is not yet multi-selectable
let (_ : GMenu.image_menu_item) =
  view_factory#add_image_item ~key:GdkKeysyms._A
    ~label:"Select all"
    ~callback:(fun () -> goals_view#selection#select_all ()) ()
 *)

let (_ : GMenu.menu_item) =
  view_factory#add_item ~key:GdkKeysyms._plus
Sylvain Dailler's avatar
Sylvain Dailler committed
635
    ~callback:(fun _ -> enlarge_fonts gconfig) "Enlarge font"
636 637 638

let (_ : GMenu.menu_item) =
    view_factory#add_item ~key:GdkKeysyms._minus
Sylvain Dailler's avatar
Sylvain Dailler committed
639
      ~callback:(fun _ -> reduce_fonts gconfig) "Reduce font"
640 641 642 643 644 645 646 647 648

let (_ : GMenu.image_menu_item) =
  view_factory#add_image_item ~key:GdkKeysyms._E
    ~label:"Expand all" ~callback:(fun () -> goals_view#expand_all ()) ()

let collapse_iter iter =
  let path = goals_model#get_path iter in
  goals_view#collapse_row path

Sylvain Dailler's avatar
Sylvain Dailler committed
649 650 651 652 653 654 655 656 657 658 659 660
let get_node_row (n: node_ID) : GTree.row_reference = Obj.magic "TODO"

let rec collapse_proven_tree (tree: session_tree) =
  match tree with
  | Node (node_ID, pos_ID, node_type, node_info, subtree_list) ->
    if node_info.proved then
      let row = get_node_row node_ID in
      collapse_iter row#iter
    else
      List.iter collapse_proven_tree subtree_list

(* TODO to remove
661 662 663 664 665 666
let rec collapse_proven_goals_from_pn pn =
  match pn_proved cont pn with
  | true  -> collapse_iter (row_from_pn pn)#iter
  | false ->
    List.iter collapse_proven_goals_from_tn
      (get_transformations cont.controller_session pn)
Sylvain Dailler's avatar
Sylvain Dailler committed
667

668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
and collapse_proven_goals_from_tn tn =
  match tn_proved cont tn with
  | true  -> collapse_iter (row_from_tn tn)#iter
  | false ->
    List.iter collapse_proven_goals_from_pn
      (get_sub_tasks cont.controller_session tn)

let collapse_proven_goals_from_th th =
  match th_proved cont th with
  | true  -> collapse_iter (row_from_th th)#iter
  | false -> List.iter collapse_proven_goals_from_pn (theory_goals th)

let collapse_proven_goals_from_file file =
  match file_proved cont file with
  | true  -> collapse_iter (row_from_file file)#iter
  | false -> List.iter collapse_proven_goals_from_th file.file_theories

let collapse_proven_goals_from_iter iter =
686
  let index = get_index iter in
687 688 689 690 691 692 693 694 695 696 697 698
  match index with
  | Inone              -> assert false
  | IproofAttempt _    -> ()
  | IproofNode pn      -> collapse_proven_goals_from_pn pn
  | Itransformation tn -> collapse_proven_goals_from_tn tn
  | Itheory th         -> collapse_proven_goals_from_th th
  | Ifile file         -> collapse_proven_goals_from_file file

let collapse_proven_goals () =
  match goals_model#get_iter_first with
  | None -> ()
  | Some root_iter -> collapse_proven_goals_from_iter root_iter
Sylvain Dailler's avatar
Sylvain Dailler committed
699
*)
700 701 702

let (_ : GMenu.image_menu_item) =
  view_factory#add_image_item ~key:GdkKeysyms._C
Sylvain Dailler's avatar
Sylvain Dailler committed
703
    ~label:"Collapse proven goals" ~callback:(fun () -> collapse_proven_tree !tree) ()
704 705 706 707 708 709 710

let () =
  Gconfig.add_modifiable_sans_font_view goals_view#misc;
  Gconfig.add_modifiable_mono_font_view monitor#misc;
  Gconfig.add_modifiable_mono_font_view task_view#misc;
  Gconfig.add_modifiable_mono_font_view command_entry#misc;
  Gconfig.add_modifiable_mono_font_view message_zone#misc;
MARCHE Claude's avatar
MARCHE Claude committed
711
  task_view#source_buffer#set_language why_lang;
Sylvain Dailler's avatar
Sylvain Dailler committed
712
  Gconfig.set_fonts gconfig
713

714 715 716 717
(******************)
(*    actions     *)
(******************)

718 719
(* TODO We currently use this for transformations etc... With strategies, we sure
   do not want to move the current index with the computing of strategy. *)
Sylvain Dailler's avatar
Sylvain Dailler committed
720
let current_selected_index = ref ""
721

722 723 724 725 726 727 728 729 730 731 732 733
let image_of_pa_status ~obsolete pa_status =
  match pa_status with
    | Controller_itp.Interrupted   -> !image_undone
    | Controller_itp.Unedited      -> !image_editor
    | Controller_itp.JustEdited    -> !image_unknown
    | Controller_itp.Scheduled     -> !image_scheduled
    | Controller_itp.Running       -> !image_running
    | Controller_itp.InternalFailure _
    | Controller_itp.Uninstalled _ -> !image_failure
    | Controller_itp.Done r        -> image_of_result ~obsolete (Some r)

let rec update_status_column_from_iter cont iter =
Sylvain Dailler's avatar
Sylvain Dailler committed
734
  set_status_column_from_cont iter;
735
  match goals_model#iter_parent iter with
736
  | Some p -> update_status_column_from_iter cont p
737 738
  | None -> ()

739 740
let move_current_row_selection_up () =
  let current_view = List.hd (goals_view#selection#get_selected_rows) in
741 742 743
  ignore (GTree.Path.up current_view);
  let row_up = goals_model#get_row_reference current_view in
  goals_view#selection#select_iter row_up#iter
744 745 746 747 748 749 750 751 752 753 754 755 756

let move_current_row_selection_down () =
  let current_iter =
    try
      let current_view = List.hd (goals_view#selection#get_selected_rows) in
      let current_row = goals_model#get_row_reference current_view in
      Some current_row#iter
    with Not_found ->
      None
  in
  let child = goals_model#iter_children current_iter in
  goals_view#selection#select_iter child

757
(* Callback of a transformation *)
Sylvain Dailler's avatar
Sylvain Dailler committed
758
(*
759 760 761 762 763 764 765 766
let callback_update_tree_transform cont status =
  match status with
  | TSdone trans_id ->
    let ses = cont.controller_session in
    let id = get_trans_parent ses trans_id in
    let row_ref = row_from_pn id in
    let r = build_subtree_from_trans cont row_ref trans_id in
    update_status_column_from_iter cont r#iter;
767 768 769 770 771 772 773 774 775 776 777 778
    (* move focus if the current index still corresponds to the
       goal *)
    let ppn = get_trans_parent cont.controller_session trans_id in
    begin match !current_selected_index with
      | IproofNode pn when pn = ppn ->
        (match Session_itp.get_sub_tasks ses trans_id with
         | first_goal :: _ ->
           (* Put the selection on the first goal *)
           goals_view#selection#select_iter (row_from_pn first_goal)#iter
         | [] -> ())
      | _ -> ()
    end;
779 780 781
  | TSfailed (id, e) ->
      message_zone#buffer#set_text
        (Pp.sprintf "%a" (get_exception_message cont.controller_session id) e)
782
  | _ -> ()
Sylvain Dailler's avatar
Sylvain Dailler committed
783
*)
784

Sylvain Dailler's avatar
Sylvain Dailler committed
785
(*
786
let rec apply_transform cont t args =
787 788
  match !current_selected_index with
  | IproofNode id ->
789
     let callback = callback_update_tree_transform cont in
790
     C.schedule_transformation cont id t args ~callback
791
  | IproofAttempt _ ->
792 793
    move_current_row_selection_up ();
    apply_transform cont t args
794
  | Itransformation _ | Ifile _ | Itheory _ | Inone ->
795 796 797 798
    begin try move_current_row_selection_down () with
      Not_found -> printf "no goals to apply transform"
    end;
    apply_transform cont t args
Sylvain Dailler's avatar
Sylvain Dailler committed
799
*)
800

Sylvain Dailler's avatar
Sylvain Dailler committed
801 802 803 804 805 806 807 808 809
(* TODO this is from tree to tree *)
(* TODO do this later
let go_to_nearest_unproven_goal_and_collapse (t: session_tree) =
  match t with
  | Node (node_ID, pos_ID, node_type, node_info, subtree_list) ->
    match node_type with
    |
*)
(*
810 811 812 813 814 815
  begin match get_first_unproven_goal_around_pn cont pn with
    | Some next_pn ->
      goals_view#selection#select_iter (row_from_pn next_pn)#iter
    | None -> ()
  end;
  collapse_proven_goals ()
Sylvain Dailler's avatar
Sylvain Dailler committed
816
*)
817

818
(* Callback of a proof_attempt *)
Sylvain Dailler's avatar
Sylvain Dailler committed
819
(*
820 821
let callback_update_tree_proof cont panid pa_status =
  let ses = cont.controller_session in
822
  let pa = get_proof_attempt_node ses panid in
MARCHE Claude's avatar
MARCHE Claude committed
823 824
  let prover = pa.prover in
  let name = Pp.string_of Whyconf.print_prover prover in
825 826
  let obsolete = pa.proof_obsolete in
  let r = match pa_status with
827 828 829 830 831 832 833 834 835
    | Scheduled ->
      begin
        try row_from_pan panid
        with Not_found ->
          let parent_id = get_proof_attempt_parent ses panid in
          let parent = row_from_pn parent_id in
          new_node ~parent name (IproofAttempt panid)
      end
    | Done _ ->
836 837 838 839 840 841 842 843 844 845
      let ppn = get_proof_attempt_parent cont.controller_session panid in
      let piter = (row_from_pn ppn)#iter in
      update_status_column_from_iter cont piter;
      (* move focus an collapse if the goal was proven and
         the current index still corresponds to the goal *)
      begin match !current_selected_index with
        | IproofNode pn when pn = ppn ->
          if pn_proved cont pn then
            go_to_nearest_unproven_goal_and_collapse pn
        | _ -> ()
846
      end;
847
      row_from_pan panid
848
    | _  -> row_from_pan panid (* TODO ? *)
849 850 851
  in
  goals_model#set ~row:r#iter ~column:status_column
    (image_of_pa_status ~obsolete pa_status)
Sylvain Dailler's avatar
Sylvain Dailler committed
852
*)
853

Sylvain Dailler's avatar
Sylvain Dailler committed
854
(*
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
let test_schedule_proof_attempt cont (p: Whyconf.config_prover) limit =
  let prover = p.Whyconf.prover in
  let callback = callback_update_tree_proof cont in
  let rec get_goals () =
    match !current_selected_index with
    | IproofNode id -> [id]
    | IproofAttempt _ ->
      move_current_row_selection_up ();
      get_goals ()
    | Itransformation tn ->
      List.rev (unproven_goals_below_tn cont [] tn)
    | Ifile file ->
      List.rev (unproven_goals_below_file cont file)
    | Itheory th ->
      List.rev (unproven_goals_below_th cont [] th)
    | Inone -> []
  in
  List.iter (fun id -> C.schedule_proof_attempt cont id prover ~limit ~callback)
    (get_goals ())
Sylvain Dailler's avatar
Sylvain Dailler committed
874
*)
MARCHE Claude's avatar
MARCHE Claude committed
875

Sylvain Dailler's avatar
Sylvain Dailler committed
876
(*
MARCHE Claude's avatar
MARCHE Claude committed
877 878 879 880 881 882 883 884 885 886 887 888 889 890
let run_strategy_on_task s =
  match !current_selected_index with
  | IproofNode id ->
     let l = Session_user_interface.strategies
               cont.controller_env gconfig.config
     in
     let st = List.filter (fun (_,c,_,_) -> c=s) l in
     begin
       match st with
       | [(n,_,_,st)] ->
          printf "running strategy '%s'@." n;
          let callback sts =
            printf "Strategy status: %a@." print_strategy_status sts
          in
MARCHE Claude's avatar
MARCHE Claude committed
891
          let callback_pa =
892
            callback_update_tree_proof cont
MARCHE Claude's avatar
MARCHE Claude committed
893 894
          in
          let callback_tr st =
895
            callback_update_tree_transform cont st
MARCHE Claude's avatar
MARCHE Claude committed
896 897
          in
          C.run_strategy_on_goal cont id st ~callback_pa ~callback_tr ~callback
MARCHE Claude's avatar
MARCHE Claude committed
898 899
    | _ -> printf "Strategy '%s' not found@." s
     end
900
  | _ -> ()
Sylvain Dailler's avatar
Sylvain Dailler committed
901
*)
MARCHE Claude's avatar
MARCHE Claude committed
902

903
let clear_command_entry () = command_entry#set_text ""
MARCHE Claude's avatar
MARCHE Claude committed
904

Sylvain Dailler's avatar
Sylvain Dailler committed
905 906 907 908
let current_node_ID () = !current_selected_index


(*
MARCHE Claude's avatar
MARCHE Claude committed
909
let interp cmd =
MARCHE Claude's avatar
MARCHE Claude committed
910 911 912 913 914
  let id =
    match !current_selected_index with
    | IproofNode id -> Some id
    | _ -> None
  in
915 916
  try
  match interp cont id cmd with
917 918
    | Transform(s,_t,args) ->
       clear_command_entry ();
919
       apply_transform cont s args
920
    | Query s ->
MARCHE Claude's avatar
MARCHE Claude committed
921
       clear_command_entry ();
922
       message_zone#buffer#set_text s
923 924 925 926 927
    | Other(s,args) ->
      begin
        match parse_prover_name gconfig.config s args with
        | Some (prover_config, limit) ->
          clear_command_entry ();
928
          test_schedule_proof_attempt cont prover_config limit
929 930
        | None ->
          match s with
MARCHE Claude's avatar
MARCHE Claude committed
931 932 933
          | "auto" ->
             let s =
               match args with
MARCHE Claude's avatar
MARCHE Claude committed
934 935
               | "2"::_ -> "2"
               | _ -> "1"
MARCHE Claude's avatar
MARCHE Claude committed
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
             in
             clear_command_entry ();
             run_strategy_on_task s
          | "help" ->
             clear_command_entry ();
             let text = Pp.sprintf
                          "Please type a command among the following (automatic completion available)@\n\
                           @\n\
                           @ <transformation name> [arguments]@\n\
                           @ <prover name> [<time limit> [<mem limit>]]@\n\
                           @ <query> [arguments]@\n\
                           @ auto [auto level]@\n\
                           @\n\
                           Available queries are:@\n@[%a@]" help_on_queries ()
             in
             message_zone#buffer#set_text text
952 953
          | _ ->
             message_zone#buffer#set_text ("unknown command '"^s^"'")
954
      end
955 956
  with e when not (Debug.test_flag Debug.stack_trace) ->
       message_zone#buffer#set_text (Pp.sprintf "anomaly: %a" Exn_printer.exn_printer e)
Sylvain Dailler's avatar
Sylvain Dailler committed
957
*)
MARCHE Claude's avatar
MARCHE Claude committed
958 959 960

let (_ : GtkSignal.id) =
  command_entry#connect#activate
Sylvain Dailler's avatar
Sylvain Dailler committed
961 962 963 964
    ~callback:(fun () ->
      add_command list_commands command_entry#text;
      let node_ID = current_node_ID () in
      P.send_request (Command command_entry#text, node_ID))
965 966


967 968 969 970 971
let get_selected_row_references () =
  List.map
    (fun path -> goals_model#get_row_reference path)
    goals_view#selection#get_selected_rows

Sylvain Dailler's avatar
Sylvain Dailler committed
972
(* TODO we now change it when notify
973 974
let on_selected_row r =
  try
975
    let session_element = get_index r#iter in
976 977
    current_selected_index := session_element;
    match session_element with
978 979
    | IproofNode id ->
       let task = get_task cont.controller_session id in
980
       let tables = get_tables cont.controller_session id in
981
       let s = Pp.string_of
982
                 (fun fmt -> Driver.print_task ~cntexample:false task_driver fmt tables)
983
                 task
Clément Fumex's avatar
Clément Fumex committed
984 985 986
       in task_view#source_buffer#set_text s;
       (* scroll to end of text *)
       task_view#scroll_to_mark `INSERT
987 988 989
    | _ -> task_view#source_buffer#set_text ""
  with
    | Not_found -> task_view#source_buffer#set_text ""
Sylvain Dailler's avatar
Sylvain Dailler committed
990 991
*)
(*
992 993 994 995 996 997
let (_ : GtkSignal.id) =
  goals_view#selection#connect#after#changed ~callback:
    (fun () ->
      match get_selected_row_references () with
        | [r] -> on_selected_row r
        | _ -> ())
Sylvain Dailler's avatar
Sylvain Dailler committed
998
*)
999 1000

(***********************)
1001
(* start the interface *)
1002
(***********************)
1003

Sylvain Dailler's avatar
Sylvain Dailler committed
1004 1005 1006
(* TODO after init this *)
let init () =
  build_tree_from_session !tree;
1007
  (* temporary *)
Sylvain Dailler's avatar
Sylvain Dailler committed
1008
  init_comp ();
Clément Fumex's avatar
Clément Fumex committed
1009
  vpan222#set_position 500;
1010
  goals_view#expand_all ();
1011 1012
  main_window#add_accel_group accel_group;
  main_window#set_icon (Some !Gconfig.why_icon);
1013
  message_zone#buffer#set_text "Welcome to Why3 IDE\ntype 'help' for help";
1014 1015
  main_window#show ();
  GMain.main ()
Sylvain Dailler's avatar
Sylvain Dailler committed
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125

exception Bad_initialization


exception Disynchronized

let change_row iter node_info : unit =
  goals_model#set ~row:iter ~column:name_column node_info.name;
  set_status_column_from_cont iter
(*  goals_model#set ~row:iter ~column:status_column image*)

(* TODO bad style on update_node functions *)
let rec update_node genealogy node_ID node_info tree =
  match tree, genealogy with
  | Node (cur_node_ID, cur_pos_ID, nt, ni, subtree_list), [] when cur_node_ID = node_ID ->
    (let n = Node (cur_node_ID, cur_pos_ID, nt, node_info, subtree_list) in
     let row = row_ref_from_node cur_node_ID in
     change_row row#iter node_info;
     n)
  | Node (cur_node_ID, cur_pos_ID, nt, ni, subtree_list), [] when cur_node_ID != node_ID ->
    (P.send_request (Get_Session_Tree, ""); raise Disynchronized)
  | Node (cur_node_ID, cur_pos_ID, nt, ni, subtree_list), hd :: tl when hd != cur_pos_ID ->
    Node (cur_node_ID, cur_pos_ID, nt, ni, subtree_list) (* TODO raise failed *)
  | Node (cur_node_ID, cur_pos_ID, nt, ni, subtree_list), hd :: tl when hd = cur_pos_ID ->
    Node (cur_node_ID, cur_pos_ID, nt, ni,
          List.map (update_node tl node_ID node_info) subtree_list)
  | t, _ -> t

let rec update_subtree genealogy node_ID subtree tree =
  match tree, genealogy with
  | Node (cur_node_ID, cur_pos_ID, nt, ni, subtree_list), [] when cur_node_ID = node_ID ->
      Node (cur_node_ID, cur_pos_ID, nt, ni, subtree :: subtree_list)
        (* TODO add side effect on goal view *)
  | Node (cur_node_ID, cur_pos_ID, nt, ni, subtree_list), [] when cur_node_ID != node_ID ->
    (P.send_request (Get_Session_Tree, ""); raise Disynchronized)
  | Node (cur_node_ID, cur_pos_ID, nt, ni, subtree_list), hd :: tl when hd != cur_pos_ID ->
    Node (cur_node_ID, cur_pos_ID, nt, ni, subtree_list) (* TODO raise failed *)
  | Node (cur_node_ID, cur_pos_ID, nt, ni, subtree_list), hd :: tl when hd = cur_pos_ID ->
    Node (cur_node_ID, cur_pos_ID, nt, ni,
          List.map (update_subtree tl node_ID subtree) subtree_list)
  | t, _ -> t

let update_tree notification =
  match notification with
  | Node_change (node_ID, node_info) ->
    let genealogy = Str.split (Str.regexp ".") node_ID in
    (try tree := update_node genealogy node_ID node_info !tree with
    | Disynchronized -> ())
  | Session_Tree (session_tree) ->
    tree := session_tree
  | New_subtree (nid, subtree) ->
    let genealogy = Str.split (Str.regexp ".") nid in
    (try tree := update_subtree genealogy nid subtree !tree with
    | Disynchronized -> ())
  | _ -> ()


let rec treat_notifs l =
  if !is_init then
    match l with
    | [] -> ()
    | Initialized _ :: tl ->
      raise Bad_initialization
    | Node_change (nid, node_info) :: tl ->
      update_tree (Node_change (nid, node_info));
      treat_notifs tl
    | New_subtree (nid, subtree) :: tl ->
      update_tree (New_subtree (nid, subtree));
      treat_notifs tl
    | Saved :: tl -> treat_notifs tl
    | Remove nid :: tl -> update_tree (Remove nid); treat_notifs tl
    | Error e :: tl -> failwith "TODO implement errors"
    | Message s :: tl -> failwith "TODO implemenbt this"
    | Session_Tree t :: tl -> update_tree (Session_Tree t)
  else
    match l with
    | [] -> ()
    | Initialized (infos, pl, trl, sl) :: tl ->
      begin
        try
          (provers_list := pl;
           transformation_list := trl;
           strategy_list := sl;
           is_init := true;
           let nc = Gconfig.load_config infos in
           Gconfig.config gconfig nc;
           Debug.dprintf debug "[GUI] Init the GTK interface...@?";
           ignore (GtkMain.Main.init ());
           Debug.dprintf debug " done.@.";
           Gconfig.init gconfig infos.main_dir;
           main_dir := infos.main_dir;
           treat_notifs tl
          )
        with e when not (Debug.test_flag Debug.stack_trace) ->
          Format.eprintf "%a@." Exn_printer.exn_printer e;
          exit 1
      end
    | _ :: tl -> treat_notifs tl


let treat_notifications () : bool =
  let l = P.get_notified () in
  treat_notifs l;
  true

  let _ = Unix_scheduler.Unix_Scheduler.idle ~prio:1 treat_notifications

end

module IDE = Make (Protocol.Protocol_why3ide)