author | Thomas Lindae <thomas.lindae@in.tum.de> |
Fri, 14 Jun 2024 10:21:28 +0200 | |
changeset 81055 | 2ca0c01164cd |
parent 81051 | 4fa6e5f9d393 |
child 81059 | fb1183184e68 |
permissions | -rw-r--r-- |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Tools/VSCode/src/dynamic_output.scala |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
3 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
4 |
Dynamic output, depending on caret focus: messages, state etc. |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
5 |
*/ |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
6 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
7 |
package isabelle.vscode |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
8 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
9 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
10 |
import isabelle._ |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
11 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
12 |
|
75393 | 13 |
object Dynamic_Output { |
72761 | 14 |
def apply(server: Language_Server): Dynamic_Output = new Dynamic_Output(server) |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
15 |
} |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
16 |
|
75393 | 17 |
class Dynamic_Output private(server: Language_Server) { |
81055
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
18 |
private val pretty_panel_ = Synchronized(None: Option[Pretty_Text_Panel]) |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
19 |
def pretty_panel: Pretty_Text_Panel = pretty_panel_.value.getOrElse(error("No Pretty Panel for Dynamic Output")) |
81041
b65931659364
lsp: added delay to dynamic_output updates after a set_margin;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81040
diff
changeset
|
20 |
|
81029
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81025
diff
changeset
|
21 |
private def handle_update(restriction: Option[Set[Command]], force: Boolean = false): Unit = { |
81055
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
22 |
val output = |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
23 |
server.resources.get_caret() match { |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
24 |
case None => Some(Nil) |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
25 |
case Some(caret) => |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
26 |
val snapshot = server.resources.snapshot(caret.model) |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
27 |
snapshot.current_command(caret.node_name, caret.offset) match { |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
28 |
case None => Some(Nil) |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
29 |
case Some(command) => |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
30 |
if (restriction.isEmpty || restriction.get.contains(command)) { |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
31 |
val output_state = server.resources.options.bool("editor_output_state") |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
32 |
Some(Rendering.output_messages(snapshot.command_results(command), output_state)) |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
33 |
} else None |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
34 |
} |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
35 |
} |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
36 |
|
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
37 |
output match { |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
38 |
case None => |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
39 |
case Some(output) => pretty_panel.refresh(output) |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
40 |
} |
81025
d4eb94b46e83
lsp: added State and Dynamic Output html_output and margin handling;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
76765
diff
changeset
|
41 |
} |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
42 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
43 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
44 |
/* main */ |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
45 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
46 |
private val main = |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
47 |
Session.Consumer[Any](getClass.getName) { |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
48 |
case changed: Session.Commands_Changed => |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
49 |
handle_update(if (changed.assignment) None else Some(changed.commands)) |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
50 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
51 |
case Session.Caret_Focus => |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
52 |
handle_update(None) |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
53 |
} |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
54 |
|
75393 | 55 |
def init(): Unit = { |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
56 |
server.session.commands_changed += main |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
57 |
server.session.caret_focus += main |
81055
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
58 |
pretty_panel_.change(p => Some(Pretty_Text_Panel( |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
59 |
server.resources, |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
60 |
server.channel, |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
61 |
(output_text, decorations) => { server.channel.write(LSP.Dynamic_Output(output_text, decorations)) } |
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
62 |
))) |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
63 |
handle_update(None) |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
64 |
} |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
65 |
|
75393 | 66 |
def exit(): Unit = { |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
67 |
server.session.commands_changed -= main |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
68 |
server.session.caret_focus -= main |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
69 |
} |
81029
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81025
diff
changeset
|
70 |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81025
diff
changeset
|
71 |
def set_margin(margin: Double): Unit = { |
81055
2ca0c01164cd
lsp: converted dynamic output to use a pretty text panel;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
72 |
pretty_panel.update_margin(margin) |
81029
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81025
diff
changeset
|
73 |
} |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
74 |
} |