| author | wenzelm |
| Sat, 22 Mar 2025 23:03:11 +0100 | |
| changeset 82320 | 8d9b5289304c |
| parent 81394 | 95b53559af80 |
| child 82757 | 9fea73244f06 |
| permissions | -rw-r--r-- |
| 66098 | 1 |
/* Title: Tools/VSCode/src/state_panel.scala |
| 66096 | 2 |
Author: Makarius |
3 |
||
4 |
Show proof state. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.vscode |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
12 |
||
| 75393 | 13 |
object State_Panel {
|
| 66096 | 14 |
private val make_id = Counter.make() |
| 66098 | 15 |
private val instances = Synchronized(Map.empty[Counter.ID, State_Panel]) |
| 66096 | 16 |
|
|
81028
84f6f17274d0
lsp: changed State_Init notification into a request and removed State_Init_Response;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81025
diff
changeset
|
17 |
def init(id: LSP.Id, server: Language_Server): Unit = {
|
| 66098 | 18 |
val instance = new State_Panel(server) |
| 66096 | 19 |
instances.change(_ + (instance.id -> instance)) |
20 |
instance.init() |
|
|
81028
84f6f17274d0
lsp: changed State_Init notification into a request and removed State_Init_Response;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81025
diff
changeset
|
21 |
instance.init_response(id) |
| 66096 | 22 |
} |
23 |
||
| 75393 | 24 |
def exit(id: Counter.ID): Unit = {
|
| 66096 | 25 |
instances.change(map => |
26 |
map.get(id) match {
|
|
27 |
case None => map |
|
28 |
case Some(instance) => instance.exit(); map - id |
|
29 |
}) |
|
30 |
} |
|
31 |
||
32 |
def locate(id: Counter.ID): Unit = |
|
33 |
instances.value.get(id).foreach(state => |
|
34 |
state.server.editor.send_dispatcher(state.locate())) |
|
35 |
||
36 |
def update(id: Counter.ID): Unit = |
|
37 |
instances.value.get(id).foreach(state => |
|
38 |
state.server.editor.send_dispatcher(state.update())) |
|
| 66211 | 39 |
|
40 |
def auto_update(id: Counter.ID, enabled: Boolean): Unit = |
|
41 |
instances.value.get(id).foreach(state => |
|
42 |
state.server.editor.send_dispatcher(state.auto_update(Some(enabled)))) |
|
|
81029
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
43 |
|
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
44 |
def set_margin(id: Counter.ID, margin: Double): Unit = |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
45 |
instances.value.get(id).foreach(state => {
|
|
81056
ccbddf0372c4
lsp: converted state panel to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
46 |
state.pretty_panel.value.update_margin(margin) |
|
81029
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
47 |
}) |
| 66096 | 48 |
} |
49 |
||
50 |
||
| 75393 | 51 |
class State_Panel private(val server: Language_Server) {
|
| 66096 | 52 |
/* output */ |
53 |
||
| 66098 | 54 |
val id: Counter.ID = State_Panel.make_id() |
|
81042
f1e0ca5aaa6b
lsp: added decorations to state updates;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81036
diff
changeset
|
55 |
|
|
81028
84f6f17274d0
lsp: changed State_Init notification into a request and removed State_Init_Response;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81025
diff
changeset
|
56 |
private def init_response(id: LSP.Id): Unit = |
|
84f6f17274d0
lsp: changed State_Init notification into a request and removed State_Init_Response;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81025
diff
changeset
|
57 |
server.channel.write(LSP.State_Init.reply(id, this.id)) |
|
81021
89bfada3a16d
lsp: added State_Init_Response message;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
75979
diff
changeset
|
58 |
|
| 66096 | 59 |
|
60 |
/* query operation */ |
|
61 |
||
| 66397 | 62 |
private val output_active = Synchronized(true) |
| 81084 | 63 |
private val pretty_panel = |
64 |
Synchronized(Pretty_Text_Panel( |
|
65 |
server.resources, |
|
66 |
server.channel, |
|
67 |
(content, decorations) => |
|
68 |
LSP.State_Output(id, content, auto_update_enabled.value, decorations) |
|
69 |
)) |
|
| 66397 | 70 |
|
| 66096 | 71 |
private val print_state = |
72 |
new Query_Operation(server.editor, (), "print_state", _ => (), |
|
| 81394 | 73 |
(_, _, output) => |
74 |
if (output_active.value && output.nonEmpty) {
|
|
75 |
pretty_panel.value.refresh(output) |
|
| 66096 | 76 |
}) |
77 |
||
| 73340 | 78 |
def locate(): Unit = print_state.locate_query() |
| 66096 | 79 |
|
|
81056
ccbddf0372c4
lsp: converted state panel to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
80 |
def update(): Unit = {
|
| 66096 | 81 |
server.editor.current_node_snapshot(()) match {
|
82 |
case Some(snapshot) => |
|
|
81056
ccbddf0372c4
lsp: converted state panel to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
83 |
(server.editor.current_command((), snapshot), print_state.get_location) match {
|
|
ccbddf0372c4
lsp: converted state panel to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
84 |
case (Some(command1), Some(command2)) if command1.id == command2.id => |
|
ccbddf0372c4
lsp: converted state panel to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
85 |
case _ => print_state.apply_query(Nil) |
| 66096 | 86 |
} |
87 |
case None => |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
||
92 |
/* auto update */ |
|
93 |
||
94 |
private val auto_update_enabled = Synchronized(true) |
|
95 |
||
| 75393 | 96 |
def auto_update(set: Option[Boolean] = None): Unit = {
|
| 66211 | 97 |
val enabled = |
98 |
auto_update_enabled.guarded_access(a => |
|
99 |
set match {
|
|
100 |
case None => Some((a, a)) |
|
101 |
case Some(b) => Some((b, b)) |
|
102 |
}) |
|
103 |
if (enabled) update() |
|
104 |
} |
|
| 66096 | 105 |
|
106 |
||
107 |
/* main */ |
|
108 |
||
109 |
private val main = |
|
110 |
Session.Consumer[Any](getClass.getName) {
|
|
| 66099 | 111 |
case changed: Session.Commands_Changed => |
112 |
if (changed.assignment) auto_update() |
|
113 |
||
114 |
case Session.Caret_Focus => |
|
115 |
auto_update() |
|
| 66096 | 116 |
} |
117 |
||
| 75393 | 118 |
def init(): Unit = {
|
| 66096 | 119 |
server.session.commands_changed += main |
120 |
server.session.caret_focus += main |
|
121 |
server.editor.send_wait_dispatcher { print_state.activate() }
|
|
122 |
server.editor.send_dispatcher { auto_update() }
|
|
123 |
} |
|
124 |
||
| 75393 | 125 |
def exit(): Unit = {
|
| 66397 | 126 |
output_active.change(_ => false) |
| 66096 | 127 |
server.session.commands_changed -= main |
128 |
server.session.caret_focus -= main |
|
| 66397 | 129 |
server.editor.send_wait_dispatcher { print_state.deactivate() }
|
| 66096 | 130 |
} |
131 |
} |