author | paulson <lp15@cam.ac.uk> |
Fri, 08 Aug 2025 16:46:03 +0100 | |
changeset 82969 | dedd9d13c79c |
parent 82934 | 499dd5d0d50f |
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 |
|
66158 | 11 |
import java.io.{File => JFile} |
12 |
import java.nio.file.FileSystems |
|
13 |
||
72869 | 14 |
import scala.collection.immutable.SortedMap |
15 |
||
16 |
||
66158 | 17 |
|
75393 | 18 |
object Rendering { |
65101 | 19 |
/* color */ |
20 |
||
75393 | 21 |
object Color extends Enumeration { |
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65101
diff
changeset
|
22 |
// background |
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68822
diff
changeset
|
23 |
val unprocessed1, running1, canceled, bad, intensify, entity, active, active_result, |
67322 | 24 |
markdown_bullet1, markdown_bullet2, markdown_bullet3, markdown_bullet4 = Value |
71601 | 25 |
val background_colors: ValueSet = values |
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65101
diff
changeset
|
26 |
|
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65101
diff
changeset
|
27 |
// foreground |
65637 | 28 |
val quoted, antiquoted = Value |
71601 | 29 |
val foreground_colors: ValueSet = values -- background_colors |
65121 | 30 |
|
65124 | 31 |
// message underline |
65637 | 32 |
val writeln, information, warning, legacy, error = Value |
71601 | 33 |
val message_underline_colors: ValueSet = values -- background_colors -- foreground_colors |
65124 | 34 |
|
35 |
// message background |
|
65637 | 36 |
val writeln_message, information_message, tracing_message, |
37 |
warning_message, legacy_message, error_message = Value |
|
71601 | 38 |
val message_background_colors: ValueSet = |
65143 | 39 |
values -- background_colors -- foreground_colors -- message_underline_colors |
65144 | 40 |
|
41 |
// text |
|
65637 | 42 |
val main, keyword1, keyword2, keyword3, quasi_keyword, improper, operator, |
43 |
tfree, tvar, free, skolem, bound, `var`, inner_numeral, inner_quoted, |
|
69965
da5e7278286b
more markup for various text kinds, notably for nested formal comments;
wenzelm
parents:
69916
diff
changeset
|
44 |
inner_cartouche, comment1, comment2, comment3, dynamic, class_parameter, |
da5e7278286b
more markup for various text kinds, notably for nested formal comments;
wenzelm
parents:
69916
diff
changeset
|
45 |
antiquote, raw_text, plain_text = Value |
71601 | 46 |
val text_colors: ValueSet = |
65144 | 47 |
values -- background_colors -- foreground_colors -- message_underline_colors -- |
48 |
message_background_colors |
|
65911 | 49 |
|
65913 | 50 |
// text overview |
65911 | 51 |
val unprocessed, running = Value |
65913 | 52 |
val text_overview_colors = Set(unprocessed, running, error, warning) |
65101 | 53 |
} |
54 |
||
55 |
||
65190 | 56 |
/* output messages */ |
64676 | 57 |
|
58 |
val state_pri = 1 |
|
59 |
val writeln_pri = 2 |
|
60 |
val information_pri = 3 |
|
61 |
val tracing_pri = 4 |
|
62 |
val warning_pri = 5 |
|
63 |
val legacy_pri = 6 |
|
64 |
val error_pri = 7 |
|
65 |
||
66 |
val message_pri = Map( |
|
67 |
Markup.STATE -> state_pri, |
|
68 |
Markup.STATE_MESSAGE -> state_pri, |
|
69 |
Markup.WRITELN -> writeln_pri, |
|
70 |
Markup.WRITELN_MESSAGE -> writeln_pri, |
|
71 |
Markup.INFORMATION -> information_pri, |
|
72 |
Markup.INFORMATION_MESSAGE -> information_pri, |
|
73 |
Markup.TRACING -> tracing_pri, |
|
74 |
Markup.TRACING_MESSAGE -> tracing_pri, |
|
75 |
Markup.WARNING -> warning_pri, |
|
76 |
Markup.WARNING_MESSAGE -> warning_pri, |
|
77 |
Markup.LEGACY -> legacy_pri, |
|
78 |
Markup.LEGACY_MESSAGE -> legacy_pri, |
|
79 |
Markup.ERROR -> error_pri, |
|
65133 | 80 |
Markup.ERROR_MESSAGE -> error_pri |
81 |
).withDefaultValue(0) |
|
64676 | 82 |
|
65121 | 83 |
val message_underline_color = Map( |
84 |
writeln_pri -> Color.writeln, |
|
85 |
information_pri -> Color.information, |
|
86 |
warning_pri -> Color.warning, |
|
87 |
legacy_pri -> Color.legacy, |
|
88 |
error_pri -> Color.error) |
|
89 |
||
65124 | 90 |
val message_background_color = Map( |
91 |
writeln_pri -> Color.writeln_message, |
|
92 |
information_pri -> Color.information_message, |
|
93 |
tracing_pri -> Color.tracing_message, |
|
94 |
warning_pri -> Color.warning_message, |
|
95 |
legacy_pri -> Color.legacy_message, |
|
96 |
error_pri -> Color.error_message) |
|
97 |
||
64676 | 98 |
|
82932 | 99 |
/* text messages */ |
100 |
||
101 |
def text_messages( |
|
102 |
snapshot: Document.Snapshot, |
|
82933 | 103 |
range: Text.Range = Text.Range.full, |
104 |
filter: XML.Elem => Boolean = _ => true |
|
82932 | 105 |
): List[Text.Info[XML.Elem]] = { |
106 |
val results = |
|
107 |
snapshot.cumulate[Vector[Command.Results.Entry]]( |
|
108 |
range, Vector.empty, message_elements, command_states => |
|
109 |
{ |
|
110 |
case (res, Text.Info(_, elem)) => |
|
82933 | 111 |
if (filter(elem)) { |
112 |
Command.State.get_result_proper(command_states, elem.markup.properties) |
|
113 |
.map(res :+ _) |
|
114 |
} |
|
115 |
else None |
|
82932 | 116 |
}) |
117 |
||
118 |
var seen_serials = Set.empty[Long] |
|
119 |
def seen(i: Long): Boolean = { |
|
120 |
val b = seen_serials(i) |
|
121 |
seen_serials += i |
|
122 |
b |
|
123 |
} |
|
82934 | 124 |
List.from( |
125 |
for { |
|
126 |
Text.Info(range, entries) <- results.iterator |
|
127 |
(i, elem) <- entries.iterator if !seen(i) |
|
128 |
} yield Text.Info(range, elem)) |
|
82932 | 129 |
} |
130 |
||
131 |
||
65144 | 132 |
/* text color */ |
133 |
||
81558
b57996a0688c
clarified term positions and markup: syntax = true means this is via concrete syntax;
wenzelm
parents:
81555
diff
changeset
|
134 |
def get_text_color(markup: Markup): Option[Color.Value] = |
81564
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81561
diff
changeset
|
135 |
if (Markup.has_syntax(markup.properties)) None |
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81561
diff
changeset
|
136 |
else text_color.get(markup.name) |
81555 | 137 |
|
81561 | 138 |
def get_foreground_text_color(markup: Markup): Option[Color.Value] = |
139 |
foreground.get(markup.name) orElse get_text_color(markup) |
|
81559 | 140 |
|
81564
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81561
diff
changeset
|
141 |
val text_color = Map( |
65144 | 142 |
Markup.KEYWORD1 -> Color.keyword1, |
143 |
Markup.KEYWORD2 -> Color.keyword2, |
|
144 |
Markup.KEYWORD3 -> Color.keyword3, |
|
145 |
Markup.QUASI_KEYWORD -> Color.quasi_keyword, |
|
81564
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81561
diff
changeset
|
146 |
Markup.IMPROPER -> Color.improper, |
65144 | 147 |
Markup.OPERATOR -> Color.operator, |
65145 | 148 |
Markup.STRING -> Color.main, |
149 |
Markup.ALT_STRING -> Color.main, |
|
150 |
Markup.CARTOUCHE -> Color.main, |
|
65144 | 151 |
Markup.LITERAL -> Color.keyword1, |
65145 | 152 |
Markup.DELIMITER -> Color.main, |
65144 | 153 |
Markup.TFREE -> Color.tfree, |
154 |
Markup.TVAR -> Color.tvar, |
|
81564
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81561
diff
changeset
|
155 |
Markup.FREE -> Color.free, |
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81561
diff
changeset
|
156 |
Markup.SKOLEM -> Color.skolem, |
65144 | 157 |
Markup.BOUND -> Color.bound, |
65637 | 158 |
Markup.VAR -> Color.`var`, |
65144 | 159 |
Markup.INNER_STRING -> Color.inner_quoted, |
160 |
Markup.INNER_CARTOUCHE -> Color.inner_cartouche, |
|
161 |
Markup.DYNAMIC_FACT -> Color.dynamic, |
|
162 |
Markup.CLASS_PARAMETER -> Color.class_parameter, |
|
163 |
Markup.ANTIQUOTE -> Color.antiquote, |
|
69965
da5e7278286b
more markup for various text kinds, notably for nested formal comments;
wenzelm
parents:
69916
diff
changeset
|
164 |
Markup.RAW_TEXT -> Color.raw_text, |
da5e7278286b
more markup for various text kinds, notably for nested formal comments;
wenzelm
parents:
69916
diff
changeset
|
165 |
Markup.PLAIN_TEXT -> Color.plain_text, |
65144 | 166 |
Markup.ML_KEYWORD1 -> Color.keyword1, |
167 |
Markup.ML_KEYWORD2 -> Color.keyword2, |
|
168 |
Markup.ML_KEYWORD3 -> Color.keyword3, |
|
65145 | 169 |
Markup.ML_DELIMITER -> Color.main, |
65144 | 170 |
Markup.ML_NUMERAL -> Color.inner_numeral, |
171 |
Markup.ML_CHAR -> Color.inner_quoted, |
|
172 |
Markup.ML_STRING -> Color.inner_quoted, |
|
69320 | 173 |
Markup.ML_COMMENT -> Color.comment1, |
69970
b5a47478897a
clarified rendering, notably of \<^latex>CARTOUCHE in outer syntax;
wenzelm
parents:
69965
diff
changeset
|
174 |
Markup.COMMENT -> Color.comment1, |
69320 | 175 |
Markup.COMMENT1 -> Color.comment1, |
176 |
Markup.COMMENT2 -> Color.comment2, |
|
177 |
Markup.COMMENT3 -> Color.comment3) |
|
65144 | 178 |
|
81559 | 179 |
private val foreground = |
66074 | 180 |
Map( |
181 |
Markup.STRING -> Color.quoted, |
|
182 |
Markup.ALT_STRING -> Color.quoted, |
|
183 |
Markup.CARTOUCHE -> Color.quoted, |
|
184 |
Markup.ANTIQUOTED -> Color.antiquoted) |
|
185 |
||
65144 | 186 |
|
65149 | 187 |
/* tooltips */ |
65101 | 188 |
|
81651 | 189 |
def gui_name(name: String, kind: String = "", prefix: String = ""): String = |
190 |
GUI.Name(name, kind = Word.informal(kind), prefix = prefix, |
|
81655 | 191 |
style = GUI.Style_Symbol_Decoded).toString |
81651 | 192 |
|
81559 | 193 |
def get_tooltip_description(name: String): Option[String] = tooltip_description.get(name) |
194 |
||
195 |
private val tooltip_description = |
|
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
196 |
Map( |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
197 |
Markup.TOKEN_RANGE -> "inner syntax token", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
198 |
Markup.FREE -> "free variable", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
199 |
Markup.SKOLEM -> "skolem variable", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
200 |
Markup.BOUND -> "bound variable", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
201 |
Markup.VAR -> "schematic variable", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
202 |
Markup.TFREE -> "free type variable", |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
203 |
Markup.TVAR -> "schematic type variable") |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
204 |
|
65149 | 205 |
|
72900 | 206 |
/* entity focus */ |
207 |
||
75393 | 208 |
object Focus { |
72900 | 209 |
def apply(ids: Set[Long]): Focus = new Focus(ids) |
210 |
val empty: Focus = apply(Set.empty) |
|
72905 | 211 |
def make(args: List[Text.Info[Focus]]): Focus = |
73359 | 212 |
args.foldLeft(empty) { case (focus1, Text.Info(_, focus2)) => focus1 ++ focus2 } |
72927
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
213 |
|
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
214 |
val full: Focus = |
75393 | 215 |
new Focus(Set.empty) { |
72927
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
216 |
override def apply(id: Long): Boolean = true |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
217 |
override def toString: String = "Focus.full" |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
218 |
} |
72900 | 219 |
} |
220 |
||
75393 | 221 |
sealed class Focus private[Rendering](protected val rep: Set[Long]) { |
72900 | 222 |
def defined: Boolean = rep.nonEmpty |
223 |
def apply(id: Long): Boolean = rep.contains(id) |
|
224 |
def + (id: Long): Focus = if (rep.contains(id)) this else new Focus(rep + id) |
|
225 |
def ++ (other: Focus): Focus = |
|
226 |
if (this eq other) this |
|
227 |
else if (rep.isEmpty) other |
|
73359 | 228 |
else other.rep.iterator.foldLeft(this)(_ + _) |
72900 | 229 |
override def toString: String = rep.mkString("Focus(", ",", ")") |
230 |
} |
|
231 |
||
232 |
||
65149 | 233 |
/* markup elements */ |
234 |
||
81559 | 235 |
val position_elements: Markup.Elements = |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
71601
diff
changeset
|
236 |
Markup.Elements(Markup.BINDING, Markup.ENTITY, Markup.REPORT, Markup.POSITION) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
71601
diff
changeset
|
237 |
|
81559 | 238 |
val semantic_completion_elements: Markup.Elements = |
66053 | 239 |
Markup.Elements(Markup.COMPLETION, Markup.NO_COMPLETION) |
240 |
||
81559 | 241 |
val language_context_elements: Markup.Elements = |
74887 | 242 |
Markup.Elements(Markup.STRING, Markup.ALT_STRING, |
66053 | 243 |
Markup.CARTOUCHE, Markup.COMMENT, Markup.LANGUAGE, |
244 |
Markup.ML_STRING, Markup.ML_COMMENT) |
|
245 |
||
81559 | 246 |
val language_elements: Markup.Elements = Markup.Elements(Markup.LANGUAGE) |
66053 | 247 |
|
81559 | 248 |
val active_elements: Markup.Elements = |
69650 | 249 |
Markup.Elements(Markup.DIALOG, Markup.BROWSER, Markup.GRAPHVIEW, Markup.THEORY_EXPORTS, |
65149 | 250 |
Markup.SENDBACK, Markup.JEDIT_ACTION, Markup.SIMP_TRACE_PANEL) |
251 |
||
81559 | 252 |
val background_elements: Markup.Elements = |
68758 | 253 |
Document_Status.Command_Status.proper_elements + Markup.WRITELN_MESSAGE + |
65149 | 254 |
Markup.STATE_MESSAGE + Markup.INFORMATION_MESSAGE + |
255 |
Markup.TRACING_MESSAGE + Markup.WARNING_MESSAGE + |
|
256 |
Markup.LEGACY_MESSAGE + Markup.ERROR_MESSAGE + |
|
257 |
Markup.BAD + Markup.INTENSIFY + Markup.ENTITY + |
|
67322 | 258 |
Markup.Markdown_Bullet.name ++ active_elements |
65149 | 259 |
|
81559 | 260 |
val foreground_elements: Markup.Elements = Markup.Elements(foreground.keySet) |
66074 | 261 |
|
81559 | 262 |
val text_color_elements: Markup.Elements = |
81564
56075edacb10
tuned: more robust wrt. changes the Markup space;
wenzelm
parents:
81561
diff
changeset
|
263 |
Markup.Elements(text_color.keySet) |
65149 | 264 |
|
81559 | 265 |
val structure_elements: Markup.Elements = |
81300
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
266 |
Markup.Elements(Markup.NOTATION, Markup.EXPRESSION, Markup.LANGUAGE, Markup.ML_TYPING, |
81304
228f4b9d1d67
clarified rendering: entity acts as atomic notation / expression;
wenzelm
parents:
81303
diff
changeset
|
267 |
Markup.MARKDOWN_PARAGRAPH, Markup.MARKDOWN_ITEM, Markup.Markdown_List.name, Markup.ENTITY, |
81300
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
268 |
Markup.COMMAND_SPAN) |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
269 |
|
81559 | 270 |
val tooltip_elements: Markup.Elements = |
80911
8ad5e6df050b
block markup for specific notation, notably infix and binder;
wenzelm
parents:
80889
diff
changeset
|
271 |
Markup.Elements(Markup.LANGUAGE, Markup.NOTATION, Markup.EXPRESSION, Markup.TIMING, |
8ad5e6df050b
block markup for specific notation, notably infix and binder;
wenzelm
parents:
80889
diff
changeset
|
272 |
Markup.ENTITY, Markup.SORTING, Markup.TYPING, Markup.CLASS_PARAMETER, Markup.ML_TYPING, |
81303
cee03fbcec0d
more rendering for Markup.COMMAND_SPAN, following Rendering.structure_elements;
wenzelm
parents:
81300
diff
changeset
|
273 |
Markup.ML_BREAKPOINT, Markup.PATH, Markup.DOC, Markup.URL, Markup.COMMAND_SPAN, |
69648 | 274 |
Markup.MARKDOWN_PARAGRAPH, Markup.MARKDOWN_ITEM, Markup.Markdown_List.name) ++ |
81559 | 275 |
Markup.Elements(tooltip_description.keySet) |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
276 |
|
81559 | 277 |
val tooltip_message_elements: Markup.Elements = |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
278 |
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
|
279 |
Markup.BAD) |
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65126
diff
changeset
|
280 |
|
81559 | 281 |
val message_elements: Markup.Elements = Markup.Elements(message_pri.keySet) |
282 |
val warning_elements: Markup.Elements = Markup.Elements(Markup.WARNING, Markup.LEGACY) |
|
283 |
val error_elements: Markup.Elements = Markup.Elements(Markup.ERROR) |
|
71499 | 284 |
|
81559 | 285 |
val comment_elements: Markup.Elements = |
80949
97924a26a5c3
add comments to rendering, e.g. to collect them from build database;
Fabian Huch <huch@in.tum.de>
parents:
80911
diff
changeset
|
286 |
Markup.Elements(Markup.ML_COMMENT, Markup.COMMENT, Markup.COMMENT1, Markup.COMMENT2, |
97924a26a5c3
add comments to rendering, e.g. to collect them from build database;
Fabian Huch <huch@in.tum.de>
parents:
80911
diff
changeset
|
287 |
Markup.COMMENT3) |
97924a26a5c3
add comments to rendering, e.g. to collect them from build database;
Fabian Huch <huch@in.tum.de>
parents:
80911
diff
changeset
|
288 |
|
81559 | 289 |
val entity_elements: Markup.Elements = Markup.Elements(Markup.ENTITY) |
67132 | 290 |
|
81559 | 291 |
val antiquoted_elements: Markup.Elements = Markup.Elements(Markup.ANTIQUOTED) |
67336 | 292 |
|
81559 | 293 |
val meta_data_elements: Markup.Elements = |
69900 | 294 |
Markup.Elements(Markup.META_TITLE, Markup.META_CREATOR, Markup.META_CONTRIBUTOR, |
69916
3235ecdcd884
more meta data from "dcterms" (superset of "dc");
wenzelm
parents:
69900
diff
changeset
|
295 |
Markup.META_DATE, Markup.META_DESCRIPTION, Markup.META_LICENSE) |
69900 | 296 |
|
81559 | 297 |
val document_tag_elements: Markup.Elements = |
74782 | 298 |
Markup.Elements(Markup.Document_Tag.name) |
70135
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
299 |
|
81559 | 300 |
val markdown_elements: Markup.Elements = |
67336 | 301 |
Markup.Elements(Markup.MARKDOWN_PARAGRAPH, Markup.MARKDOWN_ITEM, Markup.Markdown_List.name, |
302 |
Markup.Markdown_Bullet.name) |
|
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
303 |
} |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
304 |
|
72856 | 305 |
class Rendering( |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
306 |
val snapshot: Document.Snapshot, |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
307 |
val options: Options, |
75393 | 308 |
val session: Session |
309 |
) { |
|
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
310 |
override def toString: String = "Rendering(" + snapshot.toString + ")" |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
311 |
|
72856 | 312 |
def get_text(range: Text.Range): Option[String] = None |
66114 | 313 |
|
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
314 |
|
66117 | 315 |
/* caret */ |
316 |
||
75393 | 317 |
def before_caret_range(caret: Text.Offset): Text.Range = { |
66117 | 318 |
val former_caret = snapshot.revert(caret) |
319 |
snapshot.convert(Text.Range(former_caret - 1, former_caret)) |
|
320 |
} |
|
321 |
||
322 |
||
64877 | 323 |
/* completion */ |
324 |
||
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
325 |
def semantic_completion(completed_range: Option[Text.Range], caret_range: Text.Range) |
64877 | 326 |
: Option[Text.Info[Completion.Semantic]] = |
327 |
if (snapshot.is_outdated) None |
|
328 |
else { |
|
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
329 |
snapshot.select(caret_range, Rendering.semantic_completion_elements, _ => |
64877 | 330 |
{ |
331 |
case Completion.Semantic.Info(info) => |
|
332 |
completed_range match { |
|
333 |
case Some(range0) if range0.contains(info.range) && range0 != info.range => None |
|
334 |
case _ => Some(info) |
|
335 |
} |
|
336 |
case _ => None |
|
337 |
}).headOption.map(_.info) |
|
338 |
} |
|
339 |
||
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
340 |
def semantic_completion_result( |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
341 |
history: Completion.History, |
66055 | 342 |
unicode: Boolean, |
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
343 |
completed_range: Option[Text.Range], |
75393 | 344 |
caret_range: Text.Range |
345 |
): (Boolean, Option[Completion.Result]) = { |
|
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
346 |
semantic_completion(completed_range, caret_range) match { |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
347 |
case Some(Text.Info(_, Completion.No_Completion)) => (true, None) |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
348 |
case Some(Text.Info(range, names: Completion.Names)) => |
72856 | 349 |
get_text(range) match { |
66055 | 350 |
case Some(original) => (false, names.complete(range, history, unicode, original)) |
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
351 |
case None => (false, None) |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
352 |
} |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
353 |
case None => (false, None) |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
354 |
} |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
355 |
} |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
66053
diff
changeset
|
356 |
|
66053 | 357 |
def language_context(range: Text.Range): Option[Completion.Language_Context] = |
358 |
snapshot.select(range, Rendering.language_context_elements, _ => |
|
359 |
{ |
|
76965 | 360 |
case Text.Info(_, XML.Elem(Markup.Language(lang), _)) => |
361 |
if (lang.delimited) Some(Completion.Language_Context(lang)) else None |
|
66053 | 362 |
case Text.Info(_, elem) |
363 |
if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT => |
|
364 |
Some(Completion.Language_Context.ML_inner) |
|
365 |
case Text.Info(_, _) => |
|
366 |
Some(Completion.Language_Context.inner) |
|
367 |
}).headOption.map(_.info) |
|
368 |
||
66158 | 369 |
|
370 |
/* file-system path completion */ |
|
371 |
||
72842
6aae62f55c2b
clarified markup: support more completion, e.g. within ROOTS;
wenzelm
parents:
72729
diff
changeset
|
372 |
def language_path(range: Text.Range): Option[Text.Info[Boolean]] = |
66053 | 373 |
snapshot.select(range, Rendering.language_elements, _ => |
374 |
{ |
|
76965 | 375 |
case Text.Info(info_range, XML.Elem(Markup.Language(lang), _)) if lang.is_path => |
376 |
Some((lang.delimited, snapshot.convert(info_range))) |
|
66053 | 377 |
case _ => None |
72842
6aae62f55c2b
clarified markup: support more completion, e.g. within ROOTS;
wenzelm
parents:
72729
diff
changeset
|
378 |
}).headOption.map({ case Text.Info(_, (delimited, range)) => Text.Info(range, delimited) }) |
66053 | 379 |
|
75393 | 380 |
def path_completion(caret: Text.Offset): Option[Completion.Result] = { |
381 |
def complete(text: String): List[(String, List[String])] = { |
|
66158 | 382 |
try { |
383 |
val path = Path.explode(text) |
|
384 |
val (dir, base_name) = |
|
385 |
if (text == "" || text.endsWith("/")) (path, "") |
|
69366 | 386 |
else (path.dir, path.file_name) |
66158 | 387 |
|
76858 | 388 |
val directory = new JFile(session.resources.append_path(snapshot.node_name.master_dir, dir)) |
66158 | 389 |
val files = directory.listFiles |
390 |
if (files == null) Nil |
|
391 |
else { |
|
392 |
val ignore = |
|
66923 | 393 |
space_explode(':', options.string("completion_path_ignore")). |
66158 | 394 |
map(s => FileSystems.getDefault.getPathMatcher("glob:" + s)) |
395 |
(for { |
|
396 |
file <- files.iterator |
|
397 |
||
398 |
name = file.getName |
|
399 |
if name.startsWith(base_name) |
|
400 |
path_name = new JFile(name).toPath |
|
401 |
if !ignore.exists(matcher => matcher.matches(path_name)) |
|
402 |
||
403 |
text1 = (dir + Path.basic(name)).implode_short |
|
404 |
if text != text1 |
|
405 |
||
406 |
is_dir = new JFile(directory, name).isDirectory |
|
407 |
replacement = text1 + (if (is_dir) "/" else "") |
|
408 |
descr = List(text1, if (is_dir) "(directory)" else "(file)") |
|
409 |
} yield (replacement, descr)).take(options.int("completion_limit")).toList |
|
410 |
} |
|
411 |
} |
|
412 |
catch { case ERROR(_) => Nil } |
|
413 |
} |
|
414 |
||
415 |
def is_wrapped(s: String): Boolean = |
|
416 |
s.startsWith("\"") && s.endsWith("\"") || |
|
417 |
s.startsWith(Symbol.open_decoded) && s.endsWith(Symbol.close_decoded) |
|
418 |
||
419 |
for { |
|
72842
6aae62f55c2b
clarified markup: support more completion, e.g. within ROOTS;
wenzelm
parents:
72729
diff
changeset
|
420 |
Text.Info(r1, delimited) <- language_path(before_caret_range(caret)) |
72856 | 421 |
s1 <- get_text(r1) |
72842
6aae62f55c2b
clarified markup: support more completion, e.g. within ROOTS;
wenzelm
parents:
72729
diff
changeset
|
422 |
(r2, s2) <- |
6aae62f55c2b
clarified markup: support more completion, e.g. within ROOTS;
wenzelm
parents:
72729
diff
changeset
|
423 |
if (is_wrapped(s1)) { |
6aae62f55c2b
clarified markup: support more completion, e.g. within ROOTS;
wenzelm
parents:
72729
diff
changeset
|
424 |
Some((Text.Range(r1.start + 1, r1.stop - 1), s1.substring(1, s1.length - 1))) |
6aae62f55c2b
clarified markup: support more completion, e.g. within ROOTS;
wenzelm
parents:
72729
diff
changeset
|
425 |
} |
6aae62f55c2b
clarified markup: support more completion, e.g. within ROOTS;
wenzelm
parents:
72729
diff
changeset
|
426 |
else if (delimited) Some((r1, s1)) |
6aae62f55c2b
clarified markup: support more completion, e.g. within ROOTS;
wenzelm
parents:
72729
diff
changeset
|
427 |
else None |
66158 | 428 |
if Path.is_valid(s2) |
429 |
paths = complete(s2) |
|
430 |
if paths.nonEmpty |
|
431 |
items = paths.map(p => Completion.Item(r2, s2, "", p._2, p._1, 0, false)) |
|
432 |
} yield Completion.Result(r2, s2, false, items) |
|
433 |
} |
|
66053 | 434 |
|
64877 | 435 |
|
65139 | 436 |
/* spell checker */ |
437 |
||
76233
f3b23f4eaaac
clarified signature, to support external tools like "isabelle narration";
wenzelm
parents:
75958
diff
changeset
|
438 |
lazy val spell_checker_include: Markup.Elements = |
67395
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
439 |
Markup.Elements(space_explode(',', options.string("spell_checker_include")): _*) |
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
440 |
|
76233
f3b23f4eaaac
clarified signature, to support external tools like "isabelle narration";
wenzelm
parents:
75958
diff
changeset
|
441 |
lazy val spell_checker_exclude: Markup.Elements = |
f3b23f4eaaac
clarified signature, to support external tools like "isabelle narration";
wenzelm
parents:
75958
diff
changeset
|
442 |
Markup.Elements(space_explode(',', options.string("spell_checker_exclude")): _*) |
f3b23f4eaaac
clarified signature, to support external tools like "isabelle narration";
wenzelm
parents:
75958
diff
changeset
|
443 |
|
f3b23f4eaaac
clarified signature, to support external tools like "isabelle narration";
wenzelm
parents:
75958
diff
changeset
|
444 |
lazy val spell_checker_elements: Markup.Elements = |
f3b23f4eaaac
clarified signature, to support external tools like "isabelle narration";
wenzelm
parents:
75958
diff
changeset
|
445 |
spell_checker_include ++ spell_checker_exclude |
65139 | 446 |
|
75393 | 447 |
def spell_checker(range: Text.Range): List[Text.Info[Text.Range]] = { |
67395
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
448 |
val result = |
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
449 |
snapshot.select(range, spell_checker_elements, _ => |
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
450 |
{ |
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
451 |
case info => |
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
452 |
Some( |
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
453 |
if (spell_checker_include(info.info.name)) |
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
454 |
Some(snapshot.convert(info.range)) |
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
455 |
else None) |
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
456 |
}) |
78592 | 457 |
for (case Text.Info(range, Some(range1)) <- result) |
67395
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
458 |
yield Text.Info(range, range1) |
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
459 |
} |
65139 | 460 |
|
461 |
def spell_checker_point(range: Text.Range): Option[Text.Range] = |
|
67395
b39d596b77ce
more accurate spell-checking for nested quotations / antiquotations, notably in formal comments;
wenzelm
parents:
67336
diff
changeset
|
462 |
spell_checker(range).headOption.map(_.info) |
65139 | 463 |
|
464 |
||
65101 | 465 |
/* text background */ |
466 |
||
75393 | 467 |
def background( |
468 |
elements: Markup.Elements, |
|
469 |
range: Text.Range, |
|
470 |
focus: Rendering.Focus |
|
471 |
) : List[Text.Info[Rendering.Color.Value]] = { |
|
65101 | 472 |
for { |
473 |
Text.Info(r, result) <- |
|
474 |
snapshot.cumulate[(List[Markup], Option[Rendering.Color.Value])]( |
|
72906 | 475 |
range, (List(Markup.Empty), None), elements, |
65101 | 476 |
command_states => |
477 |
{ |
|
72925 | 478 |
case ((markups, color), Text.Info(_, XML.Elem(markup, _))) |
68758 | 479 |
if markups.nonEmpty && Document_Status.Command_Status.proper_elements(markup.name) => |
65101 | 480 |
Some((markup :: markups, color)) |
82796 | 481 |
case (_, Text.Info(_, XML.Elem(Markup.Bad(_), _))) => |
65101 | 482 |
Some((Nil, Some(Rendering.Color.bad))) |
483 |
case (_, Text.Info(_, XML.Elem(Markup(Markup.INTENSIFY, _), _))) => |
|
484 |
Some((Nil, Some(Rendering.Color.intensify))) |
|
72929 | 485 |
case (_, Text.Info(_, XML.Elem(Markup.Entity.Occ(i), _))) if focus(i) => |
72903 | 486 |
Some((Nil, Some(Rendering.Color.entity))) |
67322 | 487 |
case (_, Text.Info(_, XML.Elem(Markup.Markdown_Bullet(depth), _))) => |
65101 | 488 |
val color = |
65150 | 489 |
depth % 4 match { |
67322 | 490 |
case 1 => Rendering.Color.markdown_bullet1 |
491 |
case 2 => Rendering.Color.markdown_bullet2 |
|
492 |
case 3 => Rendering.Color.markdown_bullet3 |
|
493 |
case _ => Rendering.Color.markdown_bullet4 |
|
65101 | 494 |
} |
495 |
Some((Nil, Some(color))) |
|
72907 | 496 |
case (_, Text.Info(_, Protocol.Dialog(_, serial, result))) => |
65101 | 497 |
command_states.collectFirst( |
498 |
{ case st if st.results.defined(serial) => st.results.get(serial).get }) match |
|
499 |
{ |
|
500 |
case Some(Protocol.Dialog_Result(res)) if res == result => |
|
501 |
Some((Nil, Some(Rendering.Color.active_result))) |
|
502 |
case _ => |
|
503 |
Some((Nil, Some(Rendering.Color.active))) |
|
504 |
} |
|
505 |
case (_, Text.Info(_, elem)) => |
|
506 |
if (Rendering.active_elements(elem.name)) |
|
507 |
Some((Nil, Some(Rendering.Color.active))) |
|
508 |
else None |
|
509 |
}) |
|
510 |
color <- |
|
72925 | 511 |
result match { |
65101 | 512 |
case (markups, opt_color) if markups.nonEmpty => |
68758 | 513 |
val status = Document_Status.Command_Status.make(markups.iterator) |
65101 | 514 |
if (status.is_unprocessed) Some(Rendering.Color.unprocessed1) |
515 |
else if (status.is_running) Some(Rendering.Color.running1) |
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68822
diff
changeset
|
516 |
else if (status.is_canceled) Some(Rendering.Color.canceled) |
65101 | 517 |
else opt_color |
518 |
case (_, opt_color) => opt_color |
|
72925 | 519 |
} |
65101 | 520 |
} yield Text.Info(r, color) |
521 |
} |
|
522 |
||
523 |
||
524 |
/* text foreground */ |
|
525 |
||
526 |
def foreground(range: Text.Range): List[Text.Info[Rendering.Color.Value]] = |
|
527 |
snapshot.select(range, Rendering.foreground_elements, _ => |
|
528 |
{ |
|
66074 | 529 |
case info => Some(Rendering.foreground(info.info.name)) |
65101 | 530 |
}) |
531 |
||
532 |
||
72904 | 533 |
/* entity focus */ |
64767 | 534 |
|
72904 | 535 |
def entity_focus_defs(range: Text.Range): Rendering.Focus = |
72905 | 536 |
Rendering.Focus.make( |
537 |
snapshot.cumulate(range, Rendering.Focus.empty, Rendering.entity_elements, _ => |
|
72904 | 538 |
{ |
539 |
case (focus, Text.Info(_, XML.Elem(Markup.Entity.Def(i), _))) => Some(focus + i) |
|
540 |
case _ => None |
|
72905 | 541 |
})) |
72904 | 542 |
|
72927
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
543 |
def entity_focus(range: Text.Range, defs_focus: Rendering.Focus): Rendering.Focus = |
72905 | 544 |
Rendering.Focus.make( |
545 |
snapshot.cumulate(range, Rendering.Focus.empty, Rendering.entity_elements, _ => |
|
72904 | 546 |
{ |
547 |
case (focus, Text.Info(_, XML.Elem(Markup.Entity.Ref(i), _))) |
|
72927
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
548 |
if defs_focus(i) => Some(focus + i) |
72904 | 549 |
case _ => None |
72905 | 550 |
})) |
72904 | 551 |
|
552 |
||
553 |
/* caret focus */ |
|
64767 | 554 |
|
75393 | 555 |
def caret_focus(caret_range: Text.Range, defs_range: Text.Range): Rendering.Focus = { |
72904 | 556 |
val focus = entity_focus_defs(caret_range) |
557 |
if (focus.defined) focus |
|
72927
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
558 |
else if (defs_range == Text.Range.offside) Rendering.Focus.empty |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
559 |
else { |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
560 |
val defs_focus = |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
561 |
if (defs_range == Text.Range.full) Rendering.Focus.full |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
562 |
else entity_focus_defs(defs_range) |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
563 |
entity_focus(caret_range, defs_focus) |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
564 |
} |
64767 | 565 |
} |
566 |
||
75393 | 567 |
def caret_focus_ranges(caret_range: Text.Range, defs_range: Text.Range): List[Text.Range] = { |
72927
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
568 |
val focus = caret_focus(caret_range, defs_range) |
72926 | 569 |
if (focus.defined) { |
72927
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72926
diff
changeset
|
570 |
snapshot.cumulate[Boolean](defs_range, false, Rendering.entity_elements, _ => |
72904 | 571 |
{ |
72929 | 572 |
case (_, Text.Info(_, XML.Elem(Markup.Entity.Occ(i), _))) if focus(i) => Some(true) |
72904 | 573 |
case _ => None |
574 |
}).flatMap(info => if (info.info) Some(info.range) else None) |
|
64767 | 575 |
} |
576 |
else Nil |
|
577 |
} |
|
65121 | 578 |
|
579 |
||
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72856
diff
changeset
|
580 |
/* messages */ |
65121 | 581 |
|
75393 | 582 |
def message_underline_color( |
583 |
elements: Markup.Elements, |
|
584 |
range: Text.Range |
|
585 |
) : List[Text.Info[Rendering.Color.Value]] = { |
|
65121 | 586 |
val results = |
587 |
snapshot.cumulate[Int](range, 0, elements, _ => |
|
588 |
{ |
|
589 |
case (pri, Text.Info(_, elem)) => Some(pri max Rendering.message_pri(elem.name)) |
|
590 |
}) |
|
591 |
for { |
|
592 |
Text.Info(r, pri) <- results |
|
593 |
color <- Rendering.message_underline_color.get(pri) |
|
594 |
} yield Text.Info(r, color) |
|
595 |
} |
|
65149 | 596 |
|
597 |
||
81300
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
598 |
/* markup structure */ |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
599 |
|
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
600 |
def markup_structure( |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
601 |
elements: Markup.Elements, |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
602 |
ranges: List[Text.Range], |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
603 |
filter: Text.Markup => Boolean = _ => true |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
604 |
): List[Text.Markup] = { |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
605 |
def cumulate(range: Text.Range): List[Text.Info[Option[Text.Markup]]] = |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
606 |
snapshot.cumulate[Option[Text.Markup]](range, None, elements, _ => |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
607 |
{ |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
608 |
case (old, markup) => |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
609 |
Some(if (old.isEmpty || filter(markup)) Some(markup) else old) |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
610 |
}) |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
611 |
|
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
612 |
Library.distinct( |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
613 |
for (range <- ranges; case Text.Info(_, Some(m)) <- cumulate(range)) |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
614 |
yield m) |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
615 |
} |
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
616 |
|
42ff2b915b1d
support Isabelle/jEdit action isabelle.select_structure;
wenzelm
parents:
81205
diff
changeset
|
617 |
|
65149 | 618 |
/* tooltips */ |
619 |
||
69899 | 620 |
def timing_threshold: Double = 0.0 |
65149 | 621 |
|
622 |
private sealed case class Tooltip_Info( |
|
623 |
range: Text.Range, |
|
624 |
timing: Timing = Timing.zero, |
|
81395 | 625 |
messages: List[(Long, XML.Elem)] = Nil, |
626 |
rev_infos: List[(Boolean, Int, XML.Elem)] = Nil |
|
75393 | 627 |
) { |
81203 | 628 |
def add_timing(t: Timing): Tooltip_Info = copy(timing = timing + t) |
81395 | 629 |
def add_message(r0: Text.Range, serial: Long, msg: XML.Elem): Tooltip_Info = { |
65149 | 630 |
val r = snapshot.convert(r0) |
81395 | 631 |
if (range == r) copy(messages = (serial -> msg) :: messages) |
632 |
else copy(range = r, messages = List(serial -> msg)) |
|
65149 | 633 |
} |
81395 | 634 |
def add_info(r0: Text.Range, info: XML.Elem, |
635 |
important: Boolean = true, |
|
636 |
ord: Int = 0 |
|
637 |
): Tooltip_Info = { |
|
65149 | 638 |
val r = snapshot.convert(r0) |
81395 | 639 |
val entry = (important, ord, info) |
81205
a22af970a5f9
clarified order of tooltips: make it less dependent on report order from ML (which differs for input vs. output);
wenzelm
parents:
81204
diff
changeset
|
640 |
if (range == r) copy(rev_infos = entry :: rev_infos) |
a22af970a5f9
clarified order of tooltips: make it less dependent on report order from ML (which differs for input vs. output);
wenzelm
parents:
81204
diff
changeset
|
641 |
else copy (range = r, rev_infos = List(entry)) |
65149 | 642 |
} |
81395 | 643 |
def add_info_text(r0: Text.Range, text: String, ord: Int = 0): Tooltip_Info = |
644 |
add_info(r0, Pretty.string(text), ord = ord) |
|
67933
604da273e18d
more robust timing info: do not rely on order of markup;
wenzelm
parents:
67824
diff
changeset
|
645 |
|
81395 | 646 |
def timing_info(elem: XML.Elem): Option[XML.Elem] = |
647 |
if (elem.markup.name == Markup.TIMING) { |
|
648 |
if (timing.elapsed.seconds >= timing_threshold) { |
|
649 |
Some(Pretty.string(timing.message)) |
|
650 |
} |
|
651 |
else None |
|
67933
604da273e18d
more robust timing info: do not rely on order of markup;
wenzelm
parents:
67824
diff
changeset
|
652 |
} |
81395 | 653 |
else Some(elem) |
654 |
def infos(important: Boolean = true): List[XML.Elem] = |
|
67933
604da273e18d
more robust timing info: do not rely on order of markup;
wenzelm
parents:
67824
diff
changeset
|
655 |
for { |
81395 | 656 |
(is_important, _, elem) <- rev_infos.reverse.sortBy(_._2) if is_important == important |
657 |
elem1 <- timing_info(elem) |
|
658 |
} yield elem1 |
|
65149 | 659 |
} |
660 |
||
65488 | 661 |
def perhaps_append_file(node_name: Document.Node.Name, name: String): String = |
76858 | 662 |
if (Path.is_valid(name)) session.resources.append_path(node_name.master_dir, Path.explode(name)) |
76663 | 663 |
else name |
65487 | 664 |
|
81395 | 665 |
def tooltips(elements: Markup.Elements, range: Text.Range): Option[Text.Info[List[XML.Elem]]] = { |
65149 | 666 |
val results = |
67824
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67395
diff
changeset
|
667 |
snapshot.cumulate[Tooltip_Info](range, Tooltip_Info(range), elements, command_states => |
65149 | 668 |
{ |
81203 | 669 |
case (info, Text.Info(_, XML.Elem(Markup.Timing(t), _))) => Some(info.add_timing(t)) |
65149 | 670 |
|
82796 | 671 |
case (info, Text.Info(r0, msg @ XML.Elem(Markup.Bad(i), body))) |
81203 | 672 |
if body.nonEmpty => Some(info.add_message(r0, i, msg)) |
67824
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67395
diff
changeset
|
673 |
|
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67395
diff
changeset
|
674 |
case (info, Text.Info(r0, XML.Elem(Markup(name, props), _))) |
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67395
diff
changeset
|
675 |
if Rendering.tooltip_message_elements(name) => |
81395 | 676 |
for ((i, msg) <- Command.State.get_result_proper(command_states, props)) |
677 |
yield info.add_message(r0, i, msg) |
|
65149 | 678 |
|
679 |
case (info, Text.Info(r0, XML.Elem(Markup.Entity(kind, name), _))) |
|
680 |
if kind != "" && kind != Markup.ML_DEF => |
|
81651 | 681 |
val txt = Rendering.gui_name(name, kind = kind) |
682 |
val info1 = info.add_info_text(r0, txt, ord = 2) |
|
81204 | 683 |
Some(if (kind == Markup.COMMAND) info1.add_info(r0, XML.elem(Markup.TIMING)) else info1) |
65149 | 684 |
|
685 |
case (info, Text.Info(r0, XML.Elem(Markup.Path(name), _))) => |
|
65488 | 686 |
val file = perhaps_append_file(snapshot.node_name, name) |
81397 | 687 |
val info1 = |
688 |
if (name == file) info |
|
81651 | 689 |
else info.add_info_text(r0, Rendering.gui_name(name, kind = "path")) |
690 |
Some(info1.add_info_text(r0, Rendering.gui_name(file, kind = "file"))) |
|
65149 | 691 |
|
692 |
case (info, Text.Info(r0, XML.Elem(Markup.Doc(name), _))) => |
|
81651 | 693 |
Some(info.add_info_text(r0, Rendering.gui_name(name, kind = "doc"))) |
65149 | 694 |
|
695 |
case (info, Text.Info(r0, XML.Elem(Markup.Url(name), _))) => |
|
81651 | 696 |
Some(info.add_info_text(r0, Rendering.gui_name(name, kind = "URL"))) |
65149 | 697 |
|
81303
cee03fbcec0d
more rendering for Markup.COMMAND_SPAN, following Rendering.structure_elements;
wenzelm
parents:
81300
diff
changeset
|
698 |
case (info, Text.Info(r0, XML.Elem(Markup.Command_Span(span), _))) => |
81651 | 699 |
Some(info.add_info_text(r0, Rendering.gui_name(span.name, kind = Markup.COMMAND_SPAN))) |
81303
cee03fbcec0d
more rendering for Markup.COMMAND_SPAN, following Rendering.structure_elements;
wenzelm
parents:
81300
diff
changeset
|
700 |
|
65149 | 701 |
case (info, Text.Info(r0, XML.Elem(Markup(name, _), body))) |
702 |
if name == Markup.SORTING || name == Markup.TYPING => |
|
81205
a22af970a5f9
clarified order of tooltips: make it less dependent on report order from ML (which differs for input vs. output);
wenzelm
parents:
81204
diff
changeset
|
703 |
Some(info.add_info(r0, Pretty.block(XML.Text("::") :: Pretty.brk(1) :: body), ord = 3)) |
65149 | 704 |
|
705 |
case (info, Text.Info(r0, XML.Elem(Markup(Markup.CLASS_PARAMETER, _), body))) => |
|
81204 | 706 |
Some(info.add_info(r0, Pretty.block(body, indent = 0))) |
65149 | 707 |
|
708 |
case (info, Text.Info(r0, XML.Elem(Markup(Markup.ML_TYPING, _), body))) => |
|
81204 | 709 |
Some(info.add_info(r0, Pretty.block(XML.Text("ML:") :: Pretty.brk(1) :: body), |
710 |
important = false)) |
|
65149 | 711 |
|
712 |
case (info, Text.Info(r0, Protocol.ML_Breakpoint(breakpoint))) => |
|
81396 | 713 |
val text = |
714 |
if (session.debugger.breakpoint_state(breakpoint)) "breakpoint (enabled)" |
|
715 |
else "breakpoint (disabled)" |
|
716 |
Some(info.add_info_text(r0, text)) |
|
81303
cee03fbcec0d
more rendering for Markup.COMMAND_SPAN, following Rendering.structure_elements;
wenzelm
parents:
81300
diff
changeset
|
717 |
|
76965 | 718 |
case (info, Text.Info(r0, XML.Elem(Markup.Language(lang), _))) => |
81395 | 719 |
Some(info.add_info_text(r0, "language: " + lang.description)) |
65149 | 720 |
|
80911
8ad5e6df050b
block markup for specific notation, notably infix and binder;
wenzelm
parents:
80889
diff
changeset
|
721 |
case (info, Text.Info(r0, XML.Elem(Markup.Notation(kind, name), _))) => |
81651 | 722 |
val description = Rendering.gui_name(name, kind = kind, prefix = Markup.NOTATION) |
723 |
Some(info.add_info_text(r0, description, ord = 1)) |
|
80911
8ad5e6df050b
block markup for specific notation, notably infix and binder;
wenzelm
parents:
80889
diff
changeset
|
724 |
|
81630
5b87f8dacd8e
more uniform Markup.notation vs. Markup.expression;
wenzelm
parents:
81564
diff
changeset
|
725 |
case (info, Text.Info(r0, XML.Elem(Markup.Expression(kind, name), _))) => |
81651 | 726 |
val description = Rendering.gui_name(name, kind = kind, prefix = Markup.EXPRESSION) |
727 |
Some(info.add_info_text(r0, description, ord = 1)) |
|
65149 | 728 |
|
729 |
case (info, Text.Info(r0, XML.Elem(Markup(Markup.MARKDOWN_PARAGRAPH, _), _))) => |
|
81395 | 730 |
Some(info.add_info_text(r0, "Markdown: paragraph")) |
67323
d02208cefbdb
PIDE markup for Markdown items (which may consist of multiple paragraphs or lists);
wenzelm
parents:
67322
diff
changeset
|
731 |
case (info, Text.Info(r0, XML.Elem(Markup(Markup.MARKDOWN_ITEM, _), _))) => |
81395 | 732 |
Some(info.add_info_text(r0, "Markdown: item")) |
65149 | 733 |
case (info, Text.Info(r0, XML.Elem(Markup.Markdown_List(kind), _))) => |
81395 | 734 |
Some(info.add_info_text(r0, "Markdown: " + kind)) |
65149 | 735 |
|
736 |
case (info, Text.Info(r0, XML.Elem(Markup(name, _), _))) => |
|
81559 | 737 |
Rendering.get_tooltip_description(name).map(desc => info.add_info_text(r0, desc)) |
65149 | 738 |
}).map(_.info) |
739 |
||
740 |
if (results.isEmpty) None |
|
741 |
else { |
|
742 |
val r = Text.Range(results.head.range.start, results.last.range.stop) |
|
743 |
val all_tips = |
|
81395 | 744 |
results.flatMap(_.messages).foldLeft(SortedMap.empty[Long, XML.Elem])(_ + _) |
72869 | 745 |
.iterator.map(_._2).toList ::: |
81204 | 746 |
results.flatMap(res => res.infos()) ::: |
747 |
results.flatMap(res => res.infos(important = false)).lastOption.toList |
|
65149 | 748 |
if (all_tips.isEmpty) None else Some(Text.Info(r, all_tips)) |
749 |
} |
|
750 |
} |
|
65911 | 751 |
|
752 |
||
71499 | 753 |
/* messages */ |
754 |
||
755 |
def warnings(range: Text.Range): List[Text.Markup] = |
|
756 |
snapshot.select(range, Rendering.warning_elements, _ => Some(_)).map(_.info) |
|
757 |
||
758 |
def errors(range: Text.Range): List[Text.Markup] = |
|
759 |
snapshot.select(range, Rendering.error_elements, _ => Some(_)).map(_.info) |
|
760 |
||
761 |
||
80949
97924a26a5c3
add comments to rendering, e.g. to collect them from build database;
Fabian Huch <huch@in.tum.de>
parents:
80911
diff
changeset
|
762 |
/* comments */ |
97924a26a5c3
add comments to rendering, e.g. to collect them from build database;
Fabian Huch <huch@in.tum.de>
parents:
80911
diff
changeset
|
763 |
|
97924a26a5c3
add comments to rendering, e.g. to collect them from build database;
Fabian Huch <huch@in.tum.de>
parents:
80911
diff
changeset
|
764 |
def comments(range: Text.Range): List[Text.Markup] = |
97924a26a5c3
add comments to rendering, e.g. to collect them from build database;
Fabian Huch <huch@in.tum.de>
parents:
80911
diff
changeset
|
765 |
snapshot.select(range, Rendering.comment_elements, _ => Some(_)).map(_.info) |
97924a26a5c3
add comments to rendering, e.g. to collect them from build database;
Fabian Huch <huch@in.tum.de>
parents:
80911
diff
changeset
|
766 |
|
97924a26a5c3
add comments to rendering, e.g. to collect them from build database;
Fabian Huch <huch@in.tum.de>
parents:
80911
diff
changeset
|
767 |
|
65911 | 768 |
/* command status overview */ |
769 |
||
75393 | 770 |
def overview_color(range: Text.Range): Option[Rendering.Color.Value] = { |
65911 | 771 |
if (snapshot.is_outdated) None |
772 |
else { |
|
773 |
val results = |
|
68758 | 774 |
snapshot.cumulate[List[Markup]](range, Nil, Document_Status.Command_Status.liberal_elements, |
775 |
_ => |
|
776 |
{ |
|
777 |
case (status, Text.Info(_, elem)) => Some(elem.markup :: status) |
|
778 |
}, status = true) |
|
65911 | 779 |
if (results.isEmpty) None |
780 |
else { |
|
68758 | 781 |
val status = Document_Status.Command_Status.make(results.iterator.flatMap(_.info)) |
65911 | 782 |
|
783 |
if (status.is_running) Some(Rendering.Color.running) |
|
784 |
else if (status.is_failed) Some(Rendering.Color.error) |
|
785 |
else if (status.is_warned) Some(Rendering.Color.warning) |
|
786 |
else if (status.is_unprocessed) Some(Rendering.Color.unprocessed) |
|
787 |
else None |
|
788 |
} |
|
789 |
} |
|
790 |
} |
|
67132 | 791 |
|
792 |
||
793 |
/* antiquoted text */ |
|
794 |
||
795 |
def antiquoted(range: Text.Range): Option[Text.Range] = |
|
796 |
snapshot.cumulate[Option[Text.Range]](range, None, Rendering.antiquoted_elements, _ => |
|
797 |
{ |
|
798 |
case (res, info) => if (res.isEmpty) Some(Some(info.range)) else None |
|
799 |
}).headOption.flatMap(_.info) |
|
69900 | 800 |
|
801 |
||
802 |
/* meta data */ |
|
803 |
||
75393 | 804 |
def meta_data(range: Text.Range): Properties.T = { |
69900 | 805 |
val results = |
806 |
snapshot.cumulate[Properties.T](range, Nil, Rendering.meta_data_elements, _ => |
|
807 |
{ |
|
808 |
case (res, Text.Info(_, elem)) => |
|
809 |
val plain_text = XML.content(elem) |
|
810 |
Some((elem.name -> plain_text) :: res) |
|
811 |
}) |
|
812 |
Library.distinct(results.flatMap(_.info.reverse)) |
|
813 |
} |
|
70135
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
814 |
|
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
815 |
|
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
816 |
/* document tags */ |
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
817 |
|
75393 | 818 |
def document_tags(range: Text.Range): List[String] = { |
70135
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
819 |
val results = |
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
820 |
snapshot.cumulate[List[String]](range, Nil, Rendering.document_tag_elements, _ => |
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
821 |
{ |
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
822 |
case (res, Text.Info(_, XML.Elem(Markup.Document_Tag(name), _))) => Some(name :: res) |
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
823 |
case _ => None |
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
824 |
}) |
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
825 |
Library.distinct(results.flatMap(_.info.reverse)) |
ad6d4a14adb5
report document tags as seen in the text (not the active tag of Thy_Output.present_thy);
wenzelm
parents:
69970
diff
changeset
|
826 |
} |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
827 |
} |