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