author | wenzelm |
Mon, 06 Mar 2017 17:48:22 +0100 | |
changeset 65133 | 41f80c6978bc |
parent 65129 | 06a7c2d316cf |
child 65139 | 0a2c0712e432 |
permissions | -rw-r--r-- |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/PIDE/rendering.scala |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
3 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
4 |
Isabelle-specific implementation of quasi-abstract rendering and |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
5 |
markup interpretation. |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
6 |
*/ |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
7 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
8 |
package isabelle |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
9 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
10 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
11 |
object Rendering |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
12 |
{ |
65101 | 13 |
/* color */ |
14 |
||
15 |
object Color extends Enumeration |
|
16 |
{ |
|
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65101
diff
changeset
|
17 |
// background |
65101 | 18 |
val unprocessed1 = Value("unprocessed1") |
19 |
val running1 = Value("running1") |
|
20 |
val bad = Value("bad") |
|
21 |
val intensify = Value("intensify") |
|
22 |
val entity = Value("entity") |
|
23 |
val active = Value("active") |
|
24 |
val active_result = Value("active_result") |
|
25 |
val markdown_item1 = Value("markdown_item1") |
|
26 |
val markdown_item2 = Value("markdown_item2") |
|
27 |
val markdown_item3 = Value("markdown_item3") |
|
28 |
val markdown_item4 = Value("markdown_item4") |
|
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65101
diff
changeset
|
29 |
val background = values |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65101
diff
changeset
|
30 |
|
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65101
diff
changeset
|
31 |
// foreground |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65101
diff
changeset
|
32 |
val quoted = Value("quoted") |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65101
diff
changeset
|
33 |
val antiquoted = Value("antiquoted") |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65101
diff
changeset
|
34 |
val foreground = values -- background |
65121 | 35 |
|
65124 | 36 |
// message underline |
65121 | 37 |
val writeln = Value("writeln") |
38 |
val information = Value("information") |
|
39 |
val warning = Value("warning") |
|
40 |
val legacy = Value("legacy") |
|
41 |
val error = Value("error") |
|
65124 | 42 |
val message_underline = values -- background -- foreground |
43 |
||
44 |
// message background |
|
45 |
val writeln_message = Value("writeln_message") |
|
46 |
val information_message = Value("information_message") |
|
47 |
val tracing_message = Value("tracing_message") |
|
48 |
val warning_message = Value("warning_message") |
|
49 |
val legacy_message = Value("legacy_message") |
|
50 |
val error_message = Value("error_message") |
|
51 |
val message_background = values -- background -- foreground -- message_underline |
|
65101 | 52 |
} |
53 |
||
54 |
||
64676 | 55 |
/* message priorities */ |
56 |
||
57 |
val state_pri = 1 |
|
58 |
val writeln_pri = 2 |
|
59 |
val information_pri = 3 |
|
60 |
val tracing_pri = 4 |
|
61 |
val warning_pri = 5 |
|
62 |
val legacy_pri = 6 |
|
63 |
val error_pri = 7 |
|
64 |
||
65 |
val message_pri = Map( |
|
66 |
Markup.STATE -> state_pri, |
|
67 |
Markup.STATE_MESSAGE -> state_pri, |
|
68 |
Markup.WRITELN -> writeln_pri, |
|
69 |
Markup.WRITELN_MESSAGE -> writeln_pri, |
|
70 |
Markup.INFORMATION -> information_pri, |
|
71 |
Markup.INFORMATION_MESSAGE -> information_pri, |
|
72 |
Markup.TRACING -> tracing_pri, |
|
73 |
Markup.TRACING_MESSAGE -> tracing_pri, |
|
74 |
Markup.WARNING -> warning_pri, |
|
75 |
Markup.WARNING_MESSAGE -> warning_pri, |
|
76 |
Markup.LEGACY -> legacy_pri, |
|
77 |
Markup.LEGACY_MESSAGE -> legacy_pri, |
|
78 |
Markup.ERROR -> error_pri, |
|
65133 | 79 |
Markup.ERROR_MESSAGE -> error_pri |
80 |
).withDefaultValue(0) |
|
64676 | 81 |
|
65121 | 82 |
val message_underline_color = Map( |
83 |
writeln_pri -> Color.writeln, |
|
84 |
information_pri -> Color.information, |
|
85 |
warning_pri -> Color.warning, |
|
86 |
legacy_pri -> Color.legacy, |
|
87 |
error_pri -> Color.error) |
|
88 |
||
65124 | 89 |
val message_background_color = Map( |
90 |
writeln_pri -> Color.writeln_message, |
|
91 |
information_pri -> Color.information_message, |
|
92 |
tracing_pri -> Color.tracing_message, |
|
93 |
warning_pri -> Color.warning_message, |
|
94 |
legacy_pri -> Color.legacy_message, |
|
95 |
error_pri -> Color.error_message) |
|
96 |
||
64676 | 97 |
|
98 |
/* markup elements */ |
|
99 |
||
65101 | 100 |
val active_elements = |
101 |
Markup.Elements(Markup.DIALOG, Markup.BROWSER, Markup.GRAPHVIEW, |
|
102 |
Markup.SENDBACK, Markup.JEDIT_ACTION, Markup.SIMP_TRACE_PANEL) |
|
103 |
||
104 |
private val background_elements = |
|
105 |
Protocol.proper_status_elements + Markup.WRITELN_MESSAGE + |
|
106 |
Markup.STATE_MESSAGE + Markup.INFORMATION_MESSAGE + |
|
107 |
Markup.TRACING_MESSAGE + Markup.WARNING_MESSAGE + |
|
108 |
Markup.LEGACY_MESSAGE + Markup.ERROR_MESSAGE + |
|
109 |
Markup.BAD + Markup.INTENSIFY + Markup.ENTITY + |
|
110 |
Markup.Markdown_Item.name ++ active_elements |
|
111 |
||
112 |
private val foreground_elements = |
|
113 |
Markup.Elements(Markup.STRING, Markup.ALT_STRING, Markup.VERBATIM, |
|
114 |
Markup.CARTOUCHE, Markup.ANTIQUOTED) |
|
115 |
||
64877 | 116 |
private val semantic_completion_elements = |
117 |
Markup.Elements(Markup.COMPLETION, Markup.NO_COMPLETION) |
|
118 |
||
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
119 |
private val tooltip_descriptions = |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
120 |
Map( |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
121 |
Markup.CITATION -> "citation", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
122 |
Markup.TOKEN_RANGE -> "inner syntax token", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
123 |
Markup.FREE -> "free variable", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
124 |
Markup.SKOLEM -> "skolem variable", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
125 |
Markup.BOUND -> "bound variable", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
126 |
Markup.VAR -> "schematic variable", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
127 |
Markup.TFREE -> "free type variable", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
128 |
Markup.TVAR -> "schematic type variable") |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
129 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
130 |
val tooltip_elements = |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
131 |
Markup.Elements(Markup.LANGUAGE, Markup.EXPRESSION, Markup.TIMING, Markup.ENTITY, |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
132 |
Markup.SORTING, Markup.TYPING, Markup.CLASS_PARAMETER, Markup.ML_TYPING, |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
133 |
Markup.ML_BREAKPOINT, Markup.PATH, Markup.DOC, Markup.URL, Markup.MARKDOWN_PARAGRAPH, |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
134 |
Markup.Markdown_List.name) ++ Markup.Elements(tooltip_descriptions.keySet) |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
135 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
136 |
val tooltip_message_elements = |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
137 |
Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR, |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
138 |
Markup.BAD) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
139 |
|
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
140 |
private def pretty_typing(kind: String, body: XML.Body): XML.Tree = |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
141 |
Pretty.block(XML.Text(kind) :: Pretty.brk(1) :: body) |
64767 | 142 |
|
143 |
val caret_focus_elements = Markup.Elements(Markup.ENTITY) |
|
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
144 |
} |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
145 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
146 |
abstract class Rendering( |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
147 |
val snapshot: Document.Snapshot, |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
148 |
val options: Options, |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
149 |
val resources: Resources) |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
150 |
{ |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
151 |
override def toString: String = "Rendering(" + snapshot.toString + ")" |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
152 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
153 |
|
64877 | 154 |
/* completion */ |
155 |
||
156 |
def semantic_completion(completed_range: Option[Text.Range], range: Text.Range) |
|
157 |
: Option[Text.Info[Completion.Semantic]] = |
|
158 |
if (snapshot.is_outdated) None |
|
159 |
else { |
|
160 |
snapshot.select(range, Rendering.semantic_completion_elements, _ => |
|
161 |
{ |
|
162 |
case Completion.Semantic.Info(info) => |
|
163 |
completed_range match { |
|
164 |
case Some(range0) if range0.contains(info.range) && range0 != info.range => None |
|
165 |
case _ => Some(info) |
|
166 |
} |
|
167 |
case _ => None |
|
168 |
}).headOption.map(_.info) |
|
169 |
} |
|
170 |
||
171 |
||
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
172 |
/* tooltips */ |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
173 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
174 |
def timing_threshold: Double |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
175 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
176 |
private sealed case class Tooltip_Info( |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
177 |
range: Text.Range, |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
178 |
timing: Timing = Timing.zero, |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
179 |
messages: List[Command.Results.Entry] = Nil, |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
180 |
rev_infos: List[(Boolean, XML.Tree)] = Nil) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
181 |
{ |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
182 |
def + (t: Timing): Tooltip_Info = copy(timing = timing + t) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
183 |
def + (r0: Text.Range, serial: Long, tree: XML.Tree): Tooltip_Info = |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
184 |
{ |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
185 |
val r = snapshot.convert(r0) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
186 |
if (range == r) copy(messages = (serial -> tree) :: messages) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
187 |
else copy(range = r, messages = List(serial -> tree)) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
188 |
} |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
189 |
def + (r0: Text.Range, important: Boolean, tree: XML.Tree): Tooltip_Info = |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
190 |
{ |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
191 |
val r = snapshot.convert(r0) |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
192 |
if (range == r) copy(rev_infos = (important -> tree) :: rev_infos) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
193 |
else copy (range = r, rev_infos = List(important -> tree)) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
194 |
} |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
195 |
def infos(important: Boolean): List[XML.Tree] = |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
196 |
rev_infos.filter(p => p._1 == important).reverse.map(_._2) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
197 |
} |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
198 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
199 |
def tooltips(elements: Markup.Elements, range: Text.Range): Option[Text.Info[List[XML.Tree]]] = |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
200 |
{ |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
201 |
val results = |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
202 |
snapshot.cumulate[Tooltip_Info](range, Tooltip_Info(range), elements, _ => |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
203 |
{ |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
204 |
case (info, Text.Info(_, XML.Elem(Markup.Timing(t), _))) => Some(info + t) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
205 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
206 |
case (info, Text.Info(r0, XML.Elem(Markup(name, props @ Markup.Serial(serial)), body))) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
207 |
if Rendering.tooltip_message_elements(name) && body.nonEmpty => |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
208 |
Some(info + (r0, serial, XML.Elem(Markup(Markup.message(name), props), body))) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
209 |
|
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
210 |
case (info, Text.Info(r0, XML.Elem(Markup.Entity(kind, name), _))) |
64660 | 211 |
if kind != "" && kind != Markup.ML_DEF => |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
212 |
val kind1 = Word.implode(Word.explode('_', kind)) |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
213 |
val txt1 = |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
214 |
if (name == "") kind1 |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
215 |
else if (kind1 == "") quote(name) |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
216 |
else kind1 + " " + quote(name) |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
217 |
val txt2 = |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
218 |
if (kind == Markup.COMMAND && info.timing.elapsed.seconds >= timing_threshold) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
219 |
"\n" + info.timing.message |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
220 |
else "" |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
221 |
Some(info + (r0, true, XML.Text(txt1 + txt2))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
222 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
223 |
case (info, Text.Info(r0, XML.Elem(Markup.Path(name), _))) => |
64654 | 224 |
val file = resources.append_file(snapshot.node_name.master_dir, name) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
225 |
val text = |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
226 |
if (name == file) "file " + quote(file) |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
227 |
else "path " + quote(name) + "\nfile " + quote(file) |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
228 |
Some(info + (r0, true, XML.Text(text))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
229 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
230 |
case (info, Text.Info(r0, XML.Elem(Markup.Doc(name), _))) => |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
231 |
val text = "doc " + quote(name) |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
232 |
Some(info + (r0, true, XML.Text(text))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
233 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
234 |
case (info, Text.Info(r0, XML.Elem(Markup.Url(name), _))) => |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
235 |
Some(info + (r0, true, XML.Text("URL " + quote(name)))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
236 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
237 |
case (info, Text.Info(r0, XML.Elem(Markup(name, _), body))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
238 |
if name == Markup.SORTING || name == Markup.TYPING => |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
239 |
Some(info + (r0, true, Rendering.pretty_typing("::", body))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
240 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
241 |
case (info, Text.Info(r0, XML.Elem(Markup(Markup.CLASS_PARAMETER, _), body))) => |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
242 |
Some(info + (r0, true, Pretty.block(0, body))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
243 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
244 |
case (info, Text.Info(r0, XML.Elem(Markup(Markup.ML_TYPING, _), body))) => |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
245 |
Some(info + (r0, false, Rendering.pretty_typing("ML:", body))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
246 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
247 |
case (info, Text.Info(r0, Protocol.ML_Breakpoint(breakpoint))) => |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
248 |
val text = |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
249 |
if (Debugger.breakpoint_state(breakpoint)) "breakpoint (enabled)" |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
250 |
else "breakpoint (disabled)" |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
251 |
Some(info + (r0, true, XML.Text(text))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
252 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
253 |
case (info, Text.Info(r0, XML.Elem(Markup.Language(language, _, _, _), _))) => |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
254 |
val lang = Word.implode(Word.explode('_', language)) |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
255 |
Some(info + (r0, true, XML.Text("language: " + lang))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
256 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
257 |
case (info, Text.Info(r0, XML.Elem(Markup.Expression(kind), _))) => |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
258 |
val descr = if (kind == "") "expression" else "expression: " + kind |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
259 |
Some(info + (r0, true, XML.Text(descr))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
260 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
261 |
case (info, Text.Info(r0, XML.Elem(Markup(Markup.MARKDOWN_PARAGRAPH, _), _))) => |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
262 |
Some(info + (r0, true, XML.Text("Markdown: paragraph"))) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
263 |
case (info, Text.Info(r0, XML.Elem(Markup.Markdown_List(kind), _))) => |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
264 |
Some(info + (r0, true, XML.Text("Markdown: " + kind))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
265 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
266 |
case (info, Text.Info(r0, XML.Elem(Markup(name, _), _))) => |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
267 |
Rendering.tooltip_descriptions.get(name).map(desc => info + (r0, true, XML.Text(desc))) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
268 |
}).map(_.info) |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
269 |
|
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
270 |
if (results.isEmpty) None |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
271 |
else { |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
272 |
val r = Text.Range(results.head.range.start, results.last.range.stop) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
273 |
val all_tips = |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
274 |
Command.Results.make(results.flatMap(_.messages)).iterator.map(_._2).toList ::: |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
275 |
results.flatMap(res => res.infos(true)) ::: |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
276 |
results.flatMap(res => res.infos(false)).lastOption.toList |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
277 |
if (all_tips.isEmpty) None else Some(Text.Info(r, all_tips)) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
278 |
} |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
279 |
} |
64767 | 280 |
|
281 |
||
65101 | 282 |
/* text background */ |
283 |
||
284 |
def background(range: Text.Range, focus: Set[Long]): List[Text.Info[Rendering.Color.Value]] = |
|
285 |
{ |
|
286 |
for { |
|
287 |
Text.Info(r, result) <- |
|
288 |
snapshot.cumulate[(List[Markup], Option[Rendering.Color.Value])]( |
|
289 |
range, (List(Markup.Empty), None), Rendering.background_elements, |
|
290 |
command_states => |
|
291 |
{ |
|
292 |
case (((markups, color), Text.Info(_, XML.Elem(markup, _)))) |
|
293 |
if markups.nonEmpty && Protocol.proper_status_elements(markup.name) => |
|
294 |
Some((markup :: markups, color)) |
|
295 |
case (_, Text.Info(_, XML.Elem(Markup(Markup.BAD, _), _))) => |
|
296 |
Some((Nil, Some(Rendering.Color.bad))) |
|
297 |
case (_, Text.Info(_, XML.Elem(Markup(Markup.INTENSIFY, _), _))) => |
|
298 |
Some((Nil, Some(Rendering.Color.intensify))) |
|
299 |
case (_, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) => |
|
300 |
props match { |
|
301 |
case Markup.Entity.Def(i) if focus(i) => Some((Nil, Some(Rendering.Color.entity))) |
|
302 |
case Markup.Entity.Ref(i) if focus(i) => Some((Nil, Some(Rendering.Color.entity))) |
|
303 |
case _ => None |
|
304 |
} |
|
305 |
case (_, Text.Info(_, XML.Elem(Markup.Markdown_Item(depth), _))) => |
|
306 |
val color = |
|
307 |
depth match { |
|
308 |
case 1 => Rendering.Color.markdown_item1 |
|
309 |
case 2 => Rendering.Color.markdown_item2 |
|
310 |
case 3 => Rendering.Color.markdown_item3 |
|
311 |
case _ => Rendering.Color.markdown_item4 |
|
312 |
} |
|
313 |
Some((Nil, Some(color))) |
|
314 |
case (acc, Text.Info(_, Protocol.Dialog(_, serial, result))) => |
|
315 |
command_states.collectFirst( |
|
316 |
{ case st if st.results.defined(serial) => st.results.get(serial).get }) match |
|
317 |
{ |
|
318 |
case Some(Protocol.Dialog_Result(res)) if res == result => |
|
319 |
Some((Nil, Some(Rendering.Color.active_result))) |
|
320 |
case _ => |
|
321 |
Some((Nil, Some(Rendering.Color.active))) |
|
322 |
} |
|
323 |
case (_, Text.Info(_, elem)) => |
|
324 |
if (Rendering.active_elements(elem.name)) |
|
325 |
Some((Nil, Some(Rendering.Color.active))) |
|
326 |
else None |
|
327 |
}) |
|
328 |
color <- |
|
329 |
(result match { |
|
330 |
case (markups, opt_color) if markups.nonEmpty => |
|
331 |
val status = Protocol.Status.make(markups.iterator) |
|
332 |
if (status.is_unprocessed) Some(Rendering.Color.unprocessed1) |
|
333 |
else if (status.is_running) Some(Rendering.Color.running1) |
|
334 |
else opt_color |
|
335 |
case (_, opt_color) => opt_color |
|
336 |
}) |
|
337 |
} yield Text.Info(r, color) |
|
338 |
} |
|
339 |
||
340 |
||
341 |
/* text foreground */ |
|
342 |
||
343 |
def foreground(range: Text.Range): List[Text.Info[Rendering.Color.Value]] = |
|
344 |
snapshot.select(range, Rendering.foreground_elements, _ => |
|
345 |
{ |
|
346 |
case Text.Info(_, elem) => |
|
347 |
if (elem.name == Markup.ANTIQUOTED) Some(Rendering.Color.antiquoted) |
|
348 |
else Some(Rendering.Color.quoted) |
|
349 |
}) |
|
350 |
||
351 |
||
64767 | 352 |
/* caret focus */ |
353 |
||
354 |
private def entity_focus(range: Text.Range, |
|
355 |
check: (Boolean, Long) => Boolean = (is_def: Boolean, i: Long) => is_def): Set[Long] = |
|
356 |
{ |
|
357 |
val results = |
|
358 |
snapshot.cumulate[Set[Long]](range, Set.empty, Rendering.caret_focus_elements, _ => |
|
359 |
{ |
|
360 |
case (serials, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) => |
|
361 |
props match { |
|
362 |
case Markup.Entity.Def(i) if check(true, i) => Some(serials + i) |
|
363 |
case Markup.Entity.Ref(i) if check(false, i) => Some(serials + i) |
|
364 |
case _ => None |
|
365 |
} |
|
366 |
case _ => None |
|
367 |
}) |
|
368 |
(Set.empty[Long] /: results){ case (s1, Text.Info(_, s2)) => s1 ++ s2 } |
|
369 |
} |
|
370 |
||
371 |
def caret_focus(caret_range: Text.Range, visible_range: Text.Range): Set[Long] = |
|
372 |
{ |
|
373 |
val focus_defs = entity_focus(caret_range) |
|
374 |
if (focus_defs.nonEmpty) focus_defs |
|
375 |
else { |
|
376 |
val visible_defs = entity_focus(visible_range) |
|
377 |
entity_focus(caret_range, (is_def: Boolean, i: Long) => !is_def && visible_defs.contains(i)) |
|
378 |
} |
|
379 |
} |
|
380 |
||
381 |
def caret_focus_ranges(caret_range: Text.Range, visible_range: Text.Range): List[Text.Range] = |
|
382 |
{ |
|
383 |
val focus = caret_focus(caret_range, visible_range) |
|
384 |
if (focus.nonEmpty) { |
|
385 |
val results = |
|
386 |
snapshot.cumulate[Boolean](visible_range, false, Rendering.caret_focus_elements, _ => |
|
387 |
{ |
|
388 |
case (_, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) => |
|
389 |
props match { |
|
390 |
case Markup.Entity.Def(i) if focus(i) => Some(true) |
|
391 |
case Markup.Entity.Ref(i) if focus(i) => Some(true) |
|
392 |
case _ => None |
|
393 |
} |
|
394 |
}) |
|
395 |
for (info <- results if info.info) yield info.range |
|
396 |
} |
|
397 |
else Nil |
|
398 |
} |
|
65121 | 399 |
|
400 |
||
401 |
/* message underline color */ |
|
402 |
||
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
403 |
def message_underline_color(elements: Markup.Elements, range: Text.Range) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
404 |
: List[Text.Info[Rendering.Color.Value]] = |
65121 | 405 |
{ |
406 |
val results = |
|
407 |
snapshot.cumulate[Int](range, 0, elements, _ => |
|
408 |
{ |
|
409 |
case (pri, Text.Info(_, elem)) => Some(pri max Rendering.message_pri(elem.name)) |
|
410 |
}) |
|
411 |
for { |
|
412 |
Text.Info(r, pri) <- results |
|
413 |
color <- Rendering.message_underline_color.get(pri) |
|
414 |
} yield Text.Info(r, color) |
|
415 |
} |
|
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
416 |
} |