author | wenzelm |
Tue, 22 Feb 2022 11:53:06 +0100 | |
changeset 75126 | da1108a6d249 |
parent 73340 | 0ffcad1f6130 |
child 75154 | 3b5aa38282bd |
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 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
13 |
object Dynamic_Output |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
14 |
{ |
65912 | 15 |
sealed case class State(do_update: Boolean = true, output: List[XML.Tree] = Nil) |
65193 | 16 |
{ |
17 |
def handle_update( |
|
18 |
resources: VSCode_Resources, channel: Channel, restriction: Option[Set[Command]]): State = |
|
19 |
{ |
|
20 |
val st1 = |
|
65976 | 21 |
resources.get_caret() match { |
65193 | 22 |
case None => copy(output = Nil) |
66086 | 23 |
case Some(caret) => |
24 |
val snapshot = caret.model.snapshot() |
|
65193 | 25 |
if (do_update && !snapshot.is_outdated) { |
66086 | 26 |
snapshot.current_command(caret.node_name, caret.offset) match { |
65193 | 27 |
case None => copy(output = Nil) |
28 |
case Some(command) => |
|
29 |
copy(output = |
|
71383 | 30 |
if (restriction.isEmpty || restriction.get.contains(command)) |
65195 | 31 |
Rendering.output_messages(snapshot.command_results(command)) |
65193 | 32 |
else output) |
33 |
} |
|
34 |
} |
|
35 |
else this |
|
36 |
} |
|
37 |
if (st1.output != output) { |
|
75126
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
38 |
val elements = Presentation.Elements( |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
39 |
html = Presentation.elements2.html, |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
40 |
language = Presentation.elements2.language, |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
41 |
entity = Markup.Elements.full) |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
42 |
|
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
43 |
def entity_link(props: Properties.T, body: XML.Body): Option[XML.Tree] = |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
44 |
for { |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
45 |
thy_file <- Position.Def_File.unapply(props) |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
46 |
def_line <- Position.Def_Line.unapply(props) |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
47 |
source <- resources.source_file(thy_file) |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
48 |
uri = Path.explode(source).absolute_file.toURI |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
49 |
} yield HTML.link(uri.toString + "#" + def_line, body) |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
50 |
|
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
51 |
val htmlBody = Presentation.make_html( |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
52 |
Presentation.Entity_Context.empty, // FIXME |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
53 |
elements, |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
54 |
Pretty.separate(st1.output)) |
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
55 |
|
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73340
diff
changeset
|
56 |
channel.write(LSP.Dynamic_Output(HTML.source(htmlBody).toString)) |
65193 | 57 |
} |
58 |
st1 |
|
59 |
} |
|
60 |
} |
|
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
61 |
|
72761 | 62 |
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
|
63 |
} |
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 |
|
72761 | 66 |
class Dynamic_Output private(server: Language_Server) |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
67 |
{ |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
68 |
private val state = Synchronized(Dynamic_Output.State()) |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
69 |
|
73340 | 70 |
private def handle_update(restriction: Option[Set[Command]]): Unit = |
71 |
state.change(_.handle_update(server.resources, server.channel, restriction)) |
|
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
72 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
73 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
74 |
/* main */ |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
75 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
76 |
private val main = |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
77 |
Session.Consumer[Any](getClass.getName) { |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
78 |
case changed: Session.Commands_Changed => |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
79 |
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
|
80 |
|
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
81 |
case Session.Caret_Focus => |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
82 |
handle_update(None) |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
83 |
} |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
84 |
|
73340 | 85 |
def init(): Unit = |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
86 |
{ |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
87 |
server.session.commands_changed += main |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
88 |
server.session.caret_focus += main |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
89 |
handle_update(None) |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
90 |
} |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
91 |
|
73340 | 92 |
def exit(): Unit = |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
93 |
{ |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
94 |
server.session.commands_changed -= main |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
95 |
server.session.caret_focus -= main |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
96 |
} |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
diff
changeset
|
97 |
} |