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