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