src/Tools/VSCode/src/vscode_rendering.scala
changeset 64679 b2bf280b7e13
parent 64668 39a6c88c059b
child 64683 c0c09b6dfbe0
equal deleted inserted replaced
64678:914dffe59cc5 64679:b2bf280b7e13
    10 
    10 
    11 import isabelle._
    11 import isabelle._
    12 
    12 
    13 object VSCode_Rendering
    13 object VSCode_Rendering
    14 {
    14 {
       
    15   /* diagnostic messages */
       
    16 
       
    17   private val message_severity =
       
    18     Map(
       
    19       Markup.WRITELN -> Protocol.DiagnosticSeverity.Hint,
       
    20       Markup.INFORMATION -> Protocol.DiagnosticSeverity.Information,
       
    21       Markup.WARNING -> Protocol.DiagnosticSeverity.Warning,
       
    22       Markup.LEGACY -> Protocol.DiagnosticSeverity.Warning,
       
    23       Markup.ERROR -> Protocol.DiagnosticSeverity.Error,
       
    24       Markup.BAD -> Protocol.DiagnosticSeverity.Error)
       
    25 
       
    26 
       
    27   /* markup elements */
       
    28 
       
    29   private val diagnostics_elements =
       
    30     Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR,
       
    31       Markup.BAD)
       
    32 
    15   private val hyperlink_elements =
    33   private val hyperlink_elements =
    16     Markup.Elements(Markup.ENTITY, Markup.PATH, Markup.POSITION)
    34     Markup.Elements(Markup.ENTITY, Markup.PATH, Markup.POSITION)
    17 }
    35 }
    18 
    36 
    19 class VSCode_Rendering(
    37 class VSCode_Rendering(
    20     val model: Document_Model,
    38     val model: Document_Model,
    21     snapshot: Document.Snapshot,
    39     snapshot: Document.Snapshot,
    22     options: Options,
    40     options: Options,
    23     text_length: Length,
       
    24     resources: Resources)
    41     resources: Resources)
    25   extends Rendering(snapshot, options, resources)
    42   extends Rendering(snapshot, options, resources)
    26 {
    43 {
       
    44   /* diagnostics */
       
    45 
       
    46   def diagnostics: List[Text.Info[Command.Results]] =
       
    47     snapshot.cumulate[Command.Results](
       
    48       Text.Range.full, Command.Results.empty, VSCode_Rendering.diagnostics_elements, _ =>
       
    49       {
       
    50         case (res, Text.Info(_, msg @ XML.Elem(Markup(_, Markup.Serial(i)), body)))
       
    51         if body.nonEmpty => Some(res + (i -> msg))
       
    52 
       
    53         case _ => None
       
    54       })
       
    55 
       
    56   val diagnostics_margin = options.int("vscode_diagnostics_margin")
       
    57 
       
    58   def diagnostics_output(results: List[Text.Info[Command.Results]]): List[Protocol.Diagnostic] =
       
    59   {
       
    60     (for {
       
    61       Text.Info(text_range, res) <- results.iterator
       
    62       range = model.doc.range(text_range, model.text_length)
       
    63       (_, XML.Elem(Markup(name, _), body)) <- res.iterator
       
    64     } yield {
       
    65       val message = Pretty.string_of(body, margin = diagnostics_margin)
       
    66       val severity = VSCode_Rendering.message_severity.get(name)
       
    67       Protocol.Diagnostic(range, message, severity = severity)
       
    68     }).toList
       
    69   }
       
    70 
       
    71 
    27   /* tooltips */
    72   /* tooltips */
    28 
    73 
    29   def tooltip_margin: Int = options.int("vscode_tooltip_margin")
    74   def tooltip_margin: Int = options.int("vscode_tooltip_margin")
    30   def timing_threshold: Double = options.real("vscode_timing_threshold")
    75   def timing_threshold: Double = options.real("vscode_timing_threshold")
    31 
    76 
    43       Line.Node_Range(File.platform_url(name),
    88       Line.Node_Range(File.platform_url(name),
    44         opt_text match {
    89         opt_text match {
    45           case Some(text) if range.start > 0 =>
    90           case Some(text) if range.start > 0 =>
    46             val chunk = Symbol.Text_Chunk(text)
    91             val chunk = Symbol.Text_Chunk(text)
    47             val doc = Line.Document(text)
    92             val doc = Line.Document(text)
    48             def position(offset: Symbol.Offset) = doc.position(chunk.decode(offset), text_length)
    93             def position(offset: Symbol.Offset) =
       
    94               doc.position(chunk.decode(offset), model.text_length)
    49             Line.Range(position(range.start), position(range.stop))
    95             Line.Range(position(range.start), position(range.stop))
    50           case _ =>
    96           case _ =>
    51             Line.Range(Line.Position((line1 - 1) max 0))
    97             Line.Range(Line.Position((line1 - 1) max 0))
    52         })
    98         })
    53     }
    99     }