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