Skip to content

Commit 13166c2

Browse files
committed
remove the checkboxes when the incremental analysis is disabled
1 parent 8137b58 commit 13166c2

13 files changed

Lines changed: 97 additions & 39 deletions

File tree

core/agents/kappaswitchman_mpi.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ let on_message exec_command message_delimiter =
141141
Lwt.return (B (Nothing, msg_id, out))
142142
| "FileUpdateWS" ->
143143
let id =
144-
JsonUtil.read_next_item Yojson.Basic.read_string st b
144+
JsonUtil.read_next_item
145+
(JsonUtil.read_option Yojson.Basic.read_string)
146+
st b
145147
in
146148
manager#file_update_ws id >>= fun out ->
147149
Lwt.return (B (Nothing, msg_id, out))

core/api/api.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class type virtual manager_model = object
3737
method file_create : int -> string -> string -> unit result Lwt.t
3838
method file_get : string -> (string * int) result Lwt.t
3939
method file_update : string -> string -> unit result Lwt.t
40-
method file_update_ws : string -> unit result Lwt.t
40+
method file_update_ws : string option -> unit result Lwt.t
4141
method file_move : int -> string -> unit result Lwt.t
4242
method file_delete : string -> unit result Lwt.t
4343
end

core/api/api.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class type virtual manager_model = object
3333
method file_create : int -> string -> string -> unit result Lwt.t
3434
method file_get : string -> (string * int) result Lwt.t
3535
method file_update : string -> string -> unit result Lwt.t
36-
method file_update_ws : string -> unit result Lwt.t
36+
method file_update_ws : string option -> unit result Lwt.t
3737
method file_move : int -> string -> unit result Lwt.t
3838
method file_delete : string -> unit result Lwt.t
3939
end

core/api/kamoha_client.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ class virtual new_client ~post mailbox : Api.manager_model =
110110
JsonUtil.write_sequence b
111111
[
112112
(fun b -> Yojson.Basic.write_string b "FileUpdateWS");
113-
(fun b -> Yojson.Basic.write_string b file_id);
113+
(fun b ->
114+
JsonUtil.write_option Yojson.Basic.write_string b file_id);
114115
])
115116

116117
method file_move file_position file_id =

core/api/switchman_client.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ class virtual new_client ~is_running ~post mailbox =
240240
JsonUtil.write_sequence b
241241
[
242242
(fun b -> Yojson.Basic.write_string b "FileUpdateWS");
243-
(fun b -> Yojson.Basic.write_string b file_id);
243+
(fun b ->
244+
JsonUtil.write_option Yojson.Basic.write_string b file_id);
244245
])
245246

246247
method file_move file_position file_id =

core/api/switchman_client.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object
3333
string -> string -> (unit, Result_util.message list) Result_util.t Lwt.t
3434

3535
method file_update_ws :
36-
string -> (unit, Result_util.message list) Result_util.t Lwt.t
36+
string option -> (unit, Result_util.message list) Result_util.t Lwt.t
3737

3838
method get_constraints_list :
3939
( (string * Public_data.agent list Public_data.lemma list) list,

core/grammar/kamoha_mpi.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ let on_message yield post =
9595
Lwt.return (B (Nothing, msg_id, lift_answer out))
9696
| "FileUpdateWS" ->
9797
let id =
98-
JsonUtil.read_next_item Yojson.Basic.read_string st b
98+
JsonUtil.read_next_item
99+
(JsonUtil.read_option Yojson.Basic.read_string)
100+
st b
99101
in
100102
let out = Kfiles.file_set_working_set ~id catalog in
101103
Lwt.return (B (Nothing, msg_id, lift_answer out))

core/grammar/kfiles.ml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,19 @@ let file_patch ~id content catalog =
9696
Result.Ok ()
9797

9898
let file_set_working_set ~id catalog =
99-
match Hashtbl.find_all catalog.elements id with
100-
| [] -> Result.Error ("Unknown file \"" ^ id ^ "\"")
101-
| _ :: _ :: _ -> Result.Error "Serious problems in file catalog"
102-
| [ { rank; _ } ] ->
103-
let () = catalog.current_ws := Some rank in
99+
match id with
100+
| None ->
101+
let () = catalog.current_ws := None in
104102
let () = catalog.ast := Empty in
105103
Result.Ok ()
104+
| Some id ->
105+
(match Hashtbl.find_all catalog.elements id with
106+
| [] -> Result.Error ("Unknown file \"" ^ id ^ "\"")
107+
| _ :: _ :: _ -> Result.Error "Serious problems in file catalog"
108+
| [ { rank; _ } ] ->
109+
let () = catalog.current_ws := Some rank in
110+
let () = catalog.ast := Empty in
111+
Result.Ok ())
106112

107113
let file_delete ~id catalog =
108114
match Hashtbl.find_all catalog.elements id with

core/grammar/kfiles.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ val file_move :
2626
(** Fails if [position] is not available *)
2727

2828
val file_patch : id:string -> string -> catalog -> (unit, string) Result.result
29-
val file_set_working_set : id:string -> catalog -> (unit, string) result
29+
val file_set_working_set : id:string option -> catalog -> (unit, string) result
3030
val file_delete : id:string -> catalog -> (unit, string) Result.result
3131

3232
val file_get : id:string -> catalog -> (string * int, string) Result.result

gui/state/state_file.ml

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@ open Lwt.Infix
1010

1111
type slot = { local: string option; name: string }
1212
type active = { rank: int; cursor_pos: Loc.position; out_of_sync: bool }
13-
type model = { current: active option; directory: slot Mods.IntMap.t }
13+
14+
type model = {
15+
current: active option;
16+
directory: slot Mods.IntMap.t;
17+
incremental: bool;
18+
}
1419

1520
let dummy_cursor_pos = { Loc.line = -1; Loc.chr = 0 }
16-
let blank_state = { current = None; directory = Mods.IntMap.empty }
21+
22+
let blank_state =
23+
{
24+
current = None;
25+
directory = Mods.IntMap.empty;
26+
incremental =
27+
(React.S.value State_project.model).State_project.model_parameters
28+
.State_project.enable_incremental_analysis;
29+
}
30+
1731
let model_hooked, set_directory_state = Hooked.S.create blank_state
1832
let model = Hooked.S.to_react_signal model_hooked
1933

@@ -33,13 +47,27 @@ let current_filename =
3347
m.current)
3448
model
3549

36-
let is_incremental () =
37-
(React.S.value State_project.model).State_project.model_parameters
38-
.State_project.enable_incremental_analysis
50+
let is_incremental () = (React.S.value model).incremental
51+
52+
let toggle_incremental_analysis enable_incremental_analysis =
53+
let state = React.S.value model in
54+
if state.incremental <> enable_incremental_analysis then (
55+
let () =
56+
set_directory_state
57+
{ state with incremental = enable_incremental_analysis }
58+
in
59+
State_project.eval_with_project ~label:__LOC__
60+
(fun (manager : Api.concrete_manager) ->
61+
if enable_incremental_analysis then
62+
manager#file_update_ws (React.S.value current_filename)
63+
else
64+
manager#file_update_ws None)
65+
) else
66+
Lwt.return (Result_util.ok ())
3967

4068
let update_ws_if_incremental manager filename _ =
4169
if is_incremental () then
42-
manager#file_update_ws filename
70+
manager#file_update_ws (Some filename)
4371
else
4472
Lwt.return (Result_util.ok ())
4573

@@ -116,7 +144,7 @@ let update_directory ~reset current catalog =
116144
state.directory)
117145
catalog
118146
in
119-
set_directory_state { current; directory }
147+
set_directory_state { state with current; directory }
120148

121149
let create_file ~(filename : string) ~(content : string) : unit Api.lwt_result =
122150
State_project.eval_with_project ~label:"create_file" (fun manager ->
@@ -200,12 +228,13 @@ let set_content (content : string) : unit Api.lwt_result =
200228
{ local = Some content; name }
201229
state.directory
202230
in
203-
let () = set_directory_state { current = state.current; directory } in
231+
let () = set_directory_state { state with directory } in
204232
Lwt.return (Result_util.ok ())
205233
| { local = None; name } ->
206234
let () =
207235
set_directory_state
208236
{
237+
state with
209238
current =
210239
Some
211240
{
@@ -232,7 +261,7 @@ let set_compile file_id (compile : bool) : unit Api.lwt_result =
232261
let directory =
233262
Mods.IntMap.add rank { local = None; name } state.directory
234263
in
235-
let () = set_directory_state { current = state.current; directory } in
264+
let () = set_directory_state { state with directory } in
236265
State_project.eval_with_project ~label:"set_compile" (fun manager ->
237266
manager#file_create rank name content)
238267
) else
@@ -250,9 +279,7 @@ let set_compile file_id (compile : bool) : unit Api.lwt_result =
250279
{ local = Some content; name }
251280
state.directory
252281
in
253-
let () =
254-
set_directory_state { current = state.current; directory }
255-
in
282+
let () = set_directory_state { state with directory } in
256283
State_project.eval_with_project ~label:"set_compile'"
257284
(fun manager -> manager#file_delete name)
258285
) else (
@@ -271,7 +298,7 @@ let remove_file () : unit Api.lwt_result =
271298
{ rank; cursor_pos = dummy_cursor_pos; out_of_sync = false })
272299
(Mods.IntMap.root directory)
273300
in
274-
let () = set_directory_state { current; directory } in
301+
let () = set_directory_state { state with current; directory } in
275302
let x = send_refresh None in
276303
match local with
277304
| Some _ -> x
@@ -305,9 +332,9 @@ let do_a_move state file_id rank =
305332
State_project.eval_with_project ~label:"remove_file" (fun manager ->
306333
manager#file_move rank file_id
307334
>>= Api_common.result_bind_with_lwt ~ok:(fun () ->
308-
Lwt.return (Result_util.ok { current; directory })))
335+
Lwt.return (Result_util.ok { state with current; directory })))
309336
else
310-
Lwt.return (Result_util.ok { current; directory })
337+
Lwt.return (Result_util.ok { state with current; directory })
311338

312339
let rec set_position state file_id rank =
313340
match Mods.IntMap.find_option rank state.directory with
@@ -340,14 +367,14 @@ let cursor_activity ~line ~ch =
340367
| Some { rank; out_of_sync; _ } ->
341368
set_directory_state
342369
{
370+
v with
343371
current =
344372
Some
345373
{
346374
rank;
347375
cursor_pos = { Loc.line = succ line; chr = ch };
348376
out_of_sync;
349377
};
350-
directory = v.directory;
351378
}
352379

353380
let out_of_sync out_of_sync =
@@ -356,10 +383,7 @@ let out_of_sync out_of_sync =
356383
| None -> ()
357384
| Some { rank; cursor_pos; _ } ->
358385
set_directory_state
359-
{
360-
current = Some { rank; cursor_pos; out_of_sync };
361-
directory = v.directory;
362-
}
386+
{ v with current = Some { rank; cursor_pos; out_of_sync } }
363387

364388
let sync ?(reset = false) () : unit Api.lwt_result =
365389
State_project.eval_with_project ~label:"select_file" (fun manager ->

0 commit comments

Comments
 (0)