src/Tools/VSCode/src/server.scala
author wenzelm
Thu, 29 Jun 2017 15:12:40 +0200
changeset 66216 d4949bae0bad
parent 66215 9a8b6b86350c
child 66241 8f39d60b943d
permissions -rw-r--r--
clarified editor focus;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/VSCode/src/server.scala
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     3
65160
6e042537555d incremental document changes;
wenzelm
parents: 65134
diff changeset
     4
Server for VS Code Language Server Protocol 2.0/3.0, see also
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     5
https://github.com/Microsoft/language-server-protocol
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     6
https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md
65160
6e042537555d incremental document changes;
wenzelm
parents: 65134
diff changeset
     7
6e042537555d incremental document changes;
wenzelm
parents: 65134
diff changeset
     8
PIDE protocol extensions depend on system option "vscode_pide_extensions".
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     9
*/
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    10
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    11
package isabelle.vscode
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    12
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    13
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    14
import isabelle._
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    15
64710
72ca4e5f976e manage changes of external files;
wenzelm
parents: 64709
diff changeset
    16
import java.io.{PrintStream, OutputStream, File => JFile}
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    17
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    18
import scala.annotation.tailrec
65234
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
    19
import scala.collection.mutable
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    20
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    21
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    22
object Server
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    23
{
66100
d1ad5a7458c2 proper treatment of editor overlays;
wenzelm
parents: 66098
diff changeset
    24
  type Editor = isabelle.Editor[Unit]
d1ad5a7458c2 proper treatment of editor overlays;
wenzelm
parents: 66098
diff changeset
    25
d1ad5a7458c2 proper treatment of editor overlays;
wenzelm
parents: 66098
diff changeset
    26
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    27
  /* Isabelle tool wrapper */
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    28
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    29
  private lazy val default_logic = Isabelle_System.getenv("ISABELLE_LOGIC")
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    30
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    31
  val isabelle_tool = Isabelle_Tool("vscode_server", "VSCode Language Server for PIDE", args =>
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    32
  {
64644
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    33
    try {
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    34
      var log_file: Option[Path] = None
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    35
      var dirs: List[Path] = Nil
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    36
      var logic = default_logic
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    37
      var modes: List[String] = Nil
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    38
      var options = Options.init()
64733
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
    39
      var system_mode = false
65922
d2f19f05c0e9 clarified message logging;
wenzelm
parents: 65512
diff changeset
    40
      var verbose = false
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    41
64644
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    42
      val getopts = Getopts("""
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    43
Usage: isabelle vscode_server [OPTIONS]
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    44
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    45
  Options are:
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    46
    -L FILE      enable logging on FILE
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    47
    -d DIR       include session directory
64737
9fc965612459 proper default;
wenzelm
parents: 64733
diff changeset
    48
    -l NAME      logic session name (default ISABELLE_LOGIC=""" + quote(default_logic) + """)
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    49
    -m MODE      add print mode for output
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    50
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
64733
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
    51
    -s           system build mode for session image
65922
d2f19f05c0e9 clarified message logging;
wenzelm
parents: 65512
diff changeset
    52
    -v           verbose logging
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    53
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    54
  Run the VSCode Language Server protocol (JSON RPC) over stdin/stdout.
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    55
""",
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64748
diff changeset
    56
        "L:" -> (arg => log_file = Some(Path.explode(File.standard_path(arg)))),
ceb81f4928ea support for Windows;
wenzelm
parents: 64748
diff changeset
    57
        "d:" -> (arg => dirs = dirs ::: List(Path.explode(File.standard_path(arg)))),
64644
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    58
        "l:" -> (arg => logic = arg),
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    59
        "m:" -> (arg => modes = arg :: modes),
64733
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
    60
        "o:" -> (arg => options = options + arg),
65922
d2f19f05c0e9 clarified message logging;
wenzelm
parents: 65512
diff changeset
    61
        "s" -> (_ => system_mode = true),
d2f19f05c0e9 clarified message logging;
wenzelm
parents: 65512
diff changeset
    62
        "v" -> (_ => verbose = true))
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    63
64644
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    64
      val more_args = getopts(args)
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    65
      if (more_args.nonEmpty) getopts.usage()
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    66
64717
d2b50eb3d9ab tuned signature;
wenzelm
parents: 64710
diff changeset
    67
      val log = Logger.make(log_file)
65922
d2f19f05c0e9 clarified message logging;
wenzelm
parents: 65512
diff changeset
    68
      val channel = new Channel(System.in, System.out, log, verbose)
65196
e8760a98db78 discontinued pointless Text.Length: Javascript and Java agree in old-fashioned UTF-16;
wenzelm
parents: 65191
diff changeset
    69
      val server = new Server(channel, options, logic, dirs, modes, system_mode, log)
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    70
64644
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    71
      // prevent spurious garbage on the main protocol channel
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    72
      val orig_out = System.out
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    73
      try {
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    74
        System.setOut(new PrintStream(new OutputStream { def write(n: Int) {} }))
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    75
        server.start()
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    76
      }
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    77
      finally { System.setOut(orig_out) }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    78
    }
64644
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    79
    catch {
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    80
      case exn: Throwable =>
64717
d2b50eb3d9ab tuned signature;
wenzelm
parents: 64710
diff changeset
    81
        val channel = new Channel(System.in, System.out, No_Logger)
64644
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    82
        channel.error_message(Exn.message(exn))
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    83
        throw(exn)
7dbc9485ed70 more explicit error;
wenzelm
parents: 64643
diff changeset
    84
    }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    85
  })
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    86
}
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    87
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    88
class Server(
65191
4c9c83311cad dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents: 65189
diff changeset
    89
  val channel: Channel,
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    90
  options: Options,
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    91
  session_name: String = Server.default_logic,
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    92
  session_dirs: List[Path] = Nil,
64717
d2b50eb3d9ab tuned signature;
wenzelm
parents: 64710
diff changeset
    93
  modes: List[String] = Nil,
64733
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
    94
  system_mode: Boolean = false,
64717
d2b50eb3d9ab tuned signature;
wenzelm
parents: 64710
diff changeset
    95
  log: Logger = No_Logger)
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    96
{
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
    97
  server =>
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
    98
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
    99
64725
wenzelm
parents: 64724
diff changeset
   100
  /* prover session */
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   101
64703
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   102
  private val session_ = Synchronized(None: Option[Session])
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   103
  def session: Session = session_.value getOrElse error("Server inactive")
64623
83f012ce2567 clarified module name;
wenzelm
parents: 64622
diff changeset
   104
  def resources: VSCode_Resources = session.resources.asInstanceOf[VSCode_Resources]
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   105
64651
ea5620f7b0d8 clarified signature;
wenzelm
parents: 64649
diff changeset
   106
  def rendering_offset(node_pos: Line.Node_Position): Option[(VSCode_Rendering, Text.Offset)] =
64649
d67c3094a0c2 tuned signature -- more explicit types;
wenzelm
parents: 64648
diff changeset
   107
    for {
64777
ca09695eb43c clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents: 64767
diff changeset
   108
      model <- resources.get_model(new JFile(node_pos.name))
64704
08c2d80428ff re-use options from resources;
wenzelm
parents: 64703
diff changeset
   109
      rendering = model.rendering()
64830
9bc44bef99e6 more explocit Document_Model.Content;
wenzelm
parents: 64821
diff changeset
   110
      offset <- model.content.doc.offset(node_pos.pos)
64649
d67c3094a0c2 tuned signature -- more explicit types;
wenzelm
parents: 64648
diff changeset
   111
    } yield (rendering, offset)
d67c3094a0c2 tuned signature -- more explicit types;
wenzelm
parents: 64648
diff changeset
   112
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   113
  private val dynamic_output = Dynamic_Output(server)
65191
4c9c83311cad dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents: 65189
diff changeset
   114
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   115
64725
wenzelm
parents: 64724
diff changeset
   116
  /* input from client or file-system */
wenzelm
parents: 64724
diff changeset
   117
64800
415dafeb9669 manage document blobs as well;
wenzelm
parents: 64783
diff changeset
   118
  private val delay_input: Standard_Thread.Delay =
64810
05b29c8f0add more informative error for spurious crash;
wenzelm
parents: 64801
diff changeset
   119
    Standard_Thread.delay_last(options.seconds("vscode_input_delay"), channel.Error_Logger)
64725
wenzelm
parents: 64724
diff changeset
   120
    { resources.flush_input(session) }
wenzelm
parents: 64724
diff changeset
   121
64800
415dafeb9669 manage document blobs as well;
wenzelm
parents: 64783
diff changeset
   122
  private val delay_load: Standard_Thread.Delay =
64810
05b29c8f0add more informative error for spurious crash;
wenzelm
parents: 64801
diff changeset
   123
    Standard_Thread.delay_last(options.seconds("vscode_load_delay"), channel.Error_Logger) {
66100
d1ad5a7458c2 proper treatment of editor overlays;
wenzelm
parents: 66098
diff changeset
   124
      val (invoke_input, invoke_load) =
d1ad5a7458c2 proper treatment of editor overlays;
wenzelm
parents: 66098
diff changeset
   125
        resources.resolve_dependencies(session, editor, file_watcher)
64800
415dafeb9669 manage document blobs as well;
wenzelm
parents: 64783
diff changeset
   126
      if (invoke_input) delay_input.invoke()
415dafeb9669 manage document blobs as well;
wenzelm
parents: 64783
diff changeset
   127
      if (invoke_load) delay_load.invoke
415dafeb9669 manage document blobs as well;
wenzelm
parents: 64783
diff changeset
   128
    }
64727
13e37567a0d6 automatically resolve dependencies from document models and file-system;
wenzelm
parents: 64725
diff changeset
   129
64857
wenzelm
parents: 64856
diff changeset
   130
  private val file_watcher =
64727
13e37567a0d6 automatically resolve dependencies from document models and file-system;
wenzelm
parents: 64725
diff changeset
   131
    File_Watcher(sync_documents(_), options.seconds("vscode_load_delay"))
64725
wenzelm
parents: 64724
diff changeset
   132
65111
3224a6f7bd6b more robust treatment of pending input/output: these are often correlated;
wenzelm
parents: 65107
diff changeset
   133
  private def close_document(file: JFile)
3224a6f7bd6b more robust treatment of pending input/output: these are often correlated;
wenzelm
parents: 65107
diff changeset
   134
  {
3224a6f7bd6b more robust treatment of pending input/output: these are often correlated;
wenzelm
parents: 65107
diff changeset
   135
    if (resources.close_model(file)) {
3224a6f7bd6b more robust treatment of pending input/output: these are often correlated;
wenzelm
parents: 65107
diff changeset
   136
      file_watcher.register_parent(file)
65116
06d9bcb66ef3 simplified;
wenzelm
parents: 65111
diff changeset
   137
      sync_documents(Set(file))
06d9bcb66ef3 simplified;
wenzelm
parents: 65111
diff changeset
   138
      delay_input.invoke()
06d9bcb66ef3 simplified;
wenzelm
parents: 65111
diff changeset
   139
      delay_output.invoke()
65111
3224a6f7bd6b more robust treatment of pending input/output: these are often correlated;
wenzelm
parents: 65107
diff changeset
   140
    }
3224a6f7bd6b more robust treatment of pending input/output: these are often correlated;
wenzelm
parents: 65107
diff changeset
   141
  }
3224a6f7bd6b more robust treatment of pending input/output: these are often correlated;
wenzelm
parents: 65107
diff changeset
   142
65116
06d9bcb66ef3 simplified;
wenzelm
parents: 65111
diff changeset
   143
  private def sync_documents(changed: Set[JFile])
06d9bcb66ef3 simplified;
wenzelm
parents: 65111
diff changeset
   144
  {
06d9bcb66ef3 simplified;
wenzelm
parents: 65111
diff changeset
   145
    resources.sync_models(changed)
06d9bcb66ef3 simplified;
wenzelm
parents: 65111
diff changeset
   146
    delay_input.invoke()
06d9bcb66ef3 simplified;
wenzelm
parents: 65111
diff changeset
   147
    delay_output.invoke()
06d9bcb66ef3 simplified;
wenzelm
parents: 65111
diff changeset
   148
  }
64679
b2bf280b7e13 more uniform treatment of input/output wrt. client;
wenzelm
parents: 64673
diff changeset
   149
65160
6e042537555d incremental document changes;
wenzelm
parents: 65134
diff changeset
   150
  private def change_document(file: JFile, changes: List[Protocol.TextDocumentChange])
6e042537555d incremental document changes;
wenzelm
parents: 65134
diff changeset
   151
  {
65234
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   152
    val norm_changes = new mutable.ListBuffer[Protocol.TextDocumentChange]
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   153
    @tailrec def norm(chs: List[Protocol.TextDocumentChange])
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   154
    {
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   155
      if (chs.nonEmpty) {
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   156
        val (full_texts, rest1) = chs.span(_.range.isEmpty)
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   157
        val (edits, rest2) = rest1.span(_.range.nonEmpty)
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   158
        norm_changes ++= full_texts
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   159
        norm_changes ++= edits.sortBy(_.range.get.start)(Line.Position.Ordering).reverse
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   160
        norm(rest2)
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   161
      }
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   162
    }
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   163
    norm(changes)
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   164
    norm_changes.foreach(change =>
66100
d1ad5a7458c2 proper treatment of editor overlays;
wenzelm
parents: 66098
diff changeset
   165
      resources.change_model(session, editor, file, change.text, change.range))
65234
1d6e9048cb62 normalize changes strictly as specified in the protocol definition (assuming non-overlapping ranges, amending 0f555ce33970), e.g. relevant for automatic quotes/parentheses around selection;
wenzelm
parents: 65232
diff changeset
   166
64679
b2bf280b7e13 more uniform treatment of input/output wrt. client;
wenzelm
parents: 64673
diff changeset
   167
    delay_input.invoke()
65111
3224a6f7bd6b more robust treatment of pending input/output: these are often correlated;
wenzelm
parents: 65107
diff changeset
   168
    delay_output.invoke()
64679
b2bf280b7e13 more uniform treatment of input/output wrt. client;
wenzelm
parents: 64673
diff changeset
   169
  }
b2bf280b7e13 more uniform treatment of input/output wrt. client;
wenzelm
parents: 64673
diff changeset
   170
64710
72ca4e5f976e manage changes of external files;
wenzelm
parents: 64709
diff changeset
   171
65189
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   172
  /* caret handling */
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   173
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   174
  private val delay_caret_update: Standard_Thread.Delay =
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   175
    Standard_Thread.delay_last(options.seconds("vscode_input_delay"), channel.Error_Logger)
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   176
    { session.caret_focus.post(Session.Caret_Focus) }
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   177
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   178
  private def update_caret(caret: Option[(JFile, Line.Position)])
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   179
  {
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   180
    resources.update_caret(caret)
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   181
    delay_caret_update.invoke()
65926
0f7821a07aa9 restricted perspective depending on the caret -- important for reactivity when editing big files;
wenzelm
parents: 65922
diff changeset
   182
    delay_input.invoke()
65189
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   183
  }
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   184
64679
b2bf280b7e13 more uniform treatment of input/output wrt. client;
wenzelm
parents: 64673
diff changeset
   185
65983
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   186
  /* preview */
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   187
66098
5aa9cb83e70e clarified modules;
wenzelm
parents: 66096
diff changeset
   188
  private lazy val preview_panel = new Preview_Panel(resources)
65983
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   189
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   190
  private lazy val delay_preview: Standard_Thread.Delay =
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   191
    Standard_Thread.delay_last(options.seconds("vscode_output_delay"), channel.Error_Logger)
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   192
    {
66098
5aa9cb83e70e clarified modules;
wenzelm
parents: 66096
diff changeset
   193
      if (preview_panel.flush(channel)) delay_preview.invoke()
65983
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   194
    }
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   195
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   196
  private def request_preview(file: JFile, column: Int)
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   197
  {
66098
5aa9cb83e70e clarified modules;
wenzelm
parents: 66096
diff changeset
   198
    preview_panel.request(file, column)
65983
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   199
    delay_preview.invoke()
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   200
  }
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   201
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   202
64679
b2bf280b7e13 more uniform treatment of input/output wrt. client;
wenzelm
parents: 64673
diff changeset
   203
  /* output to client */
b2bf280b7e13 more uniform treatment of input/output wrt. client;
wenzelm
parents: 64673
diff changeset
   204
64691
db2b21a52f20 prefer stable state -- reduce repeated diagnostics;
wenzelm
parents: 64690
diff changeset
   205
  private val delay_output: Standard_Thread.Delay =
64810
05b29c8f0add more informative error for spurious crash;
wenzelm
parents: 64801
diff changeset
   206
    Standard_Thread.delay_last(options.seconds("vscode_output_delay"), channel.Error_Logger)
64703
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   207
    {
65232
ca571c8c0788 avoid race condition between current_state().stable_tip_version and model.rendering();
wenzelm
parents: 65231
diff changeset
   208
      if (resources.flush_output(channel)) delay_output.invoke()
64679
b2bf280b7e13 more uniform treatment of input/output wrt. client;
wenzelm
parents: 64673
diff changeset
   209
    }
b2bf280b7e13 more uniform treatment of input/output wrt. client;
wenzelm
parents: 64673
diff changeset
   210
66138
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   211
  def update_output(changed_nodes: Traversable[JFile])
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   212
  {
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   213
    resources.update_output(changed_nodes)
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   214
    delay_output.invoke()
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   215
  }
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   216
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   217
  def update_output_visible()
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   218
  {
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   219
    resources.update_output_visible()
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   220
    delay_output.invoke()
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   221
  }
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   222
64725
wenzelm
parents: 64724
diff changeset
   223
  private val prover_output =
wenzelm
parents: 64724
diff changeset
   224
    Session.Consumer[Session.Commands_Changed](getClass.getName) {
65119
a7bedf94e71c always invoke output: pending_output may be present due to other reasons;
wenzelm
parents: 65116
diff changeset
   225
      case changed =>
66138
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   226
        update_output(changed.nodes.toList.map(resources.node_file(_)))
64725
wenzelm
parents: 64724
diff changeset
   227
    }
64710
72ca4e5f976e manage changes of external files;
wenzelm
parents: 64709
diff changeset
   228
64725
wenzelm
parents: 64724
diff changeset
   229
  private val syslog =
64692
ccf017e2f2b4 support for syslog messages;
wenzelm
parents: 64691
diff changeset
   230
    Session.Consumer[Prover.Message](getClass.getName) {
ccf017e2f2b4 support for syslog messages;
wenzelm
parents: 64691
diff changeset
   231
      case output: Prover.Output if output.is_syslog =>
64870
41e2797af496 clarified text output wrt. symbols;
wenzelm
parents: 64857
diff changeset
   232
        channel.log_writeln(resources.output_xml(output.message))
64692
ccf017e2f2b4 support for syslog messages;
wenzelm
parents: 64691
diff changeset
   233
      case _ =>
ccf017e2f2b4 support for syslog messages;
wenzelm
parents: 64691
diff changeset
   234
    }
ccf017e2f2b4 support for syslog messages;
wenzelm
parents: 64691
diff changeset
   235
ccf017e2f2b4 support for syslog messages;
wenzelm
parents: 64691
diff changeset
   236
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   237
  /* init and exit */
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   238
64641
wenzelm
parents: 64623
diff changeset
   239
  def init(id: Protocol.Id)
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   240
  {
64641
wenzelm
parents: 64623
diff changeset
   241
    def reply(err: String)
wenzelm
parents: 64623
diff changeset
   242
    {
wenzelm
parents: 64623
diff changeset
   243
      channel.write(Protocol.Initialize.reply(id, err))
64642
c231206a84c8 display messages, according to regular Isabelle Output;
wenzelm
parents: 64641
diff changeset
   244
      if (err == "")
c231206a84c8 display messages, according to regular Isabelle Output;
wenzelm
parents: 64641
diff changeset
   245
        channel.writeln("Welcome to Isabelle/" + session_name + " (" + Distribution.version + ")")
c231206a84c8 display messages, according to regular Isabelle Output;
wenzelm
parents: 64641
diff changeset
   246
      else channel.error_message(err)
64641
wenzelm
parents: 64623
diff changeset
   247
    }
wenzelm
parents: 64623
diff changeset
   248
64643
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   249
    val try_session =
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   250
      try {
64733
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   251
        if (!Build.build(options = options, build_heap = true, no_build = true,
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   252
              system_mode = system_mode, dirs = session_dirs, sessions = List(session_name)).ok)
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   253
        {
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   254
          val start_msg = "Build started for Isabelle/" + session_name + " ..."
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   255
          val fail_msg = "Session build failed -- prover process remains inactive!"
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   256
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   257
          val progress = channel.make_progress(verbose = true)
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   258
          progress.echo(start_msg); channel.writeln(start_msg)
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   259
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   260
          if (!Build.build(options = options, progress = progress, build_heap = true,
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   261
              system_mode = system_mode, dirs = session_dirs, sessions = List(session_name)).ok)
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   262
          {
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   263
            progress.echo(fail_msg); error(fail_msg)
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   264
          }
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   265
        }
20174e871623 automatically build session image;
wenzelm
parents: 64727
diff changeset
   266
65512
9fd620f2fa7d always explore all sessions;
wenzelm
parents: 65361
diff changeset
   267
        val session_base =
9fd620f2fa7d always explore all sessions;
wenzelm
parents: 65361
diff changeset
   268
          Sessions.session_base(options, session_name, dirs = session_dirs, all_known = true)
65361
ecefb68dc21d tuned signature;
wenzelm
parents: 65317
diff changeset
   269
        val resources = new VSCode_Resources(options, session_base, log)
64854
f5aa712e6250 tuned signature;
wenzelm
parents: 64830
diff changeset
   270
          {
64727
13e37567a0d6 automatically resolve dependencies from document models and file-system;
wenzelm
parents: 64725
diff changeset
   271
            override def commit(change: Session.Change): Unit =
64800
415dafeb9669 manage document blobs as well;
wenzelm
parents: 64783
diff changeset
   272
              if (change.deps_changed || undefined_blobs(change.version.nodes).nonEmpty)
415dafeb9669 manage document blobs as well;
wenzelm
parents: 64783
diff changeset
   273
                delay_load.invoke()
64727
13e37567a0d6 automatically resolve dependencies from document models and file-system;
wenzelm
parents: 64725
diff changeset
   274
          }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   275
65272
7611c55c39d0 always output proof state: there is only one output buffer in Isabelle/VSCode;
wenzelm
parents: 65264
diff changeset
   276
        val session_options = options.bool("editor_output_state") = true
7611c55c39d0 always output proof state: there is only one output buffer in Isabelle/VSCode;
wenzelm
parents: 65264
diff changeset
   277
        Some(new Session(session_options, resources))
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   278
      }
64643
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   279
      catch { case ERROR(msg) => reply(msg); None }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   280
64643
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   281
    for (session <- try_session) {
65191
4c9c83311cad dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents: 65189
diff changeset
   282
      session_.change(_ => Some(session))
4c9c83311cad dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents: 65189
diff changeset
   283
65227
wenzelm
parents: 65216
diff changeset
   284
      session.commands_changed += prover_output
wenzelm
parents: 65216
diff changeset
   285
      session.all_messages += syslog
wenzelm
parents: 65216
diff changeset
   286
wenzelm
parents: 65216
diff changeset
   287
      dynamic_output.init()
wenzelm
parents: 65216
diff changeset
   288
64643
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   289
      var session_phase: Session.Consumer[Session.Phase] = null
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   290
      session_phase =
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   291
        Session.Consumer(getClass.getName) {
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   292
          case Session.Ready =>
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   293
            session.phase_changed -= session_phase
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   294
            reply("")
65317
b9f5cd845616 more informative session result;
wenzelm
parents: 65272
diff changeset
   295
          case Session.Terminated(result) if !result.ok =>
64643
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   296
            session.phase_changed -= session_phase
65317
b9f5cd845616 more informative session result;
wenzelm
parents: 65272
diff changeset
   297
            reply("Prover startup failed: return code " + result.rc)
64643
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   298
          case _ =>
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   299
        }
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   300
      session.phase_changed += session_phase
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   301
65216
060a8a1f2dec tuned signature;
wenzelm
parents: 65210
diff changeset
   302
      Isabelle_Process.start(session, options,
060a8a1f2dec tuned signature;
wenzelm
parents: 65210
diff changeset
   303
        logic = session_name, dirs = session_dirs, modes = modes)
64643
b755f6069ba2 more explicit error;
wenzelm
parents: 64642
diff changeset
   304
    }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   305
  }
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   306
64641
wenzelm
parents: 64623
diff changeset
   307
  def shutdown(id: Protocol.Id)
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   308
  {
64641
wenzelm
parents: 64623
diff changeset
   309
    def reply(err: String): Unit = channel.write(Protocol.Shutdown.reply(id, err))
wenzelm
parents: 64623
diff changeset
   310
64703
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   311
    session_.change({
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   312
      case Some(session) =>
65228
b11099b7d868 clarified shutdown;
wenzelm
parents: 65227
diff changeset
   313
        session.commands_changed -= prover_output
b11099b7d868 clarified shutdown;
wenzelm
parents: 65227
diff changeset
   314
        session.all_messages -= syslog
b11099b7d868 clarified shutdown;
wenzelm
parents: 65227
diff changeset
   315
65191
4c9c83311cad dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents: 65189
diff changeset
   316
        dynamic_output.exit()
65228
b11099b7d868 clarified shutdown;
wenzelm
parents: 65227
diff changeset
   317
b11099b7d868 clarified shutdown;
wenzelm
parents: 65227
diff changeset
   318
        delay_load.revoke()
b11099b7d868 clarified shutdown;
wenzelm
parents: 65227
diff changeset
   319
        file_watcher.shutdown()
64703
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   320
        delay_input.revoke()
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   321
        delay_output.revoke()
65228
b11099b7d868 clarified shutdown;
wenzelm
parents: 65227
diff changeset
   322
        delay_caret_update.revoke()
65983
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   323
        delay_preview.revoke()
65228
b11099b7d868 clarified shutdown;
wenzelm
parents: 65227
diff changeset
   324
b11099b7d868 clarified shutdown;
wenzelm
parents: 65227
diff changeset
   325
        val rc = session.stop()
65231
wenzelm
parents: 65229
diff changeset
   326
        if (rc == 0) reply("") else reply("Prover shutdown failed: return code " + rc)
64703
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   327
        None
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   328
      case None =>
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   329
        reply("Prover inactive")
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   330
        None
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   331
    })
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   332
  }
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   333
64646
805c5e6fa430 tuned messages;
wenzelm
parents: 64645
diff changeset
   334
  def exit() {
64717
d2b50eb3d9ab tuned signature;
wenzelm
parents: 64710
diff changeset
   335
    log("\n")
64703
a115391494ed moved main state to VSCode_Resources;
wenzelm
parents: 64702
diff changeset
   336
    sys.exit(if (session_.value.isDefined) 1 else 0)
64646
805c5e6fa430 tuned messages;
wenzelm
parents: 64645
diff changeset
   337
  }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   338
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   339
64877
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   340
  /* completion */
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   341
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   342
  def completion(id: Protocol.Id, node_pos: Line.Node_Position)
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   343
  {
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   344
    val result =
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   345
      (for ((rendering, offset) <- rendering_offset(node_pos))
66054
fb0eea226a4d more uniform syntax_completion + semantic_completion;
wenzelm
parents: 66052
diff changeset
   346
        yield rendering.completion(node_pos.pos, offset)) getOrElse Nil
64877
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   347
    channel.write(Protocol.Completion.reply(id, result))
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   348
  }
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   349
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   350
66138
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   351
  /* spell-checker dictionary */
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   352
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   353
  def update_dictionary(include: Boolean, permanent: Boolean)
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   354
  {
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   355
    for {
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   356
      spell_checker <- resources.spell_checker.get
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   357
      caret <- resources.get_caret()
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   358
      rendering = caret.model.rendering()
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   359
      range = rendering.before_caret_range(caret.offset)
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   360
      Text.Info(_, word) <- Spell_Checker.current_word(rendering, range)
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   361
    } {
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   362
      spell_checker.update(word, include, permanent)
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   363
      update_output_visible()
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   364
    }
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   365
  }
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   366
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   367
  def reset_dictionary()
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   368
  {
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   369
    for (spell_checker <- resources.spell_checker.get)
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   370
    {
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   371
      spell_checker.reset()
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   372
      update_output_visible()
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   373
    }
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   374
  }
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   375
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   376
64622
529bbb8977c7 more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents: 64618
diff changeset
   377
  /* hover */
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   378
64651
ea5620f7b0d8 clarified signature;
wenzelm
parents: 64649
diff changeset
   379
  def hover(id: Protocol.Id, node_pos: Line.Node_Position)
64641
wenzelm
parents: 64623
diff changeset
   380
  {
wenzelm
parents: 64623
diff changeset
   381
    val result =
wenzelm
parents: 64623
diff changeset
   382
      for {
64651
ea5620f7b0d8 clarified signature;
wenzelm
parents: 64649
diff changeset
   383
        (rendering, offset) <- rendering_offset(node_pos)
65134
511bf19348d3 clarified messages (with improved scalability): legacy/error as diagnostics, writeln/information/warning/bad as tooltips (dynamic hover);
wenzelm
parents: 65129
diff changeset
   384
        info <- rendering.tooltips(VSCode_Rendering.tooltip_elements, Text.Range(offset, offset + 1))
64641
wenzelm
parents: 64623
diff changeset
   385
      } yield {
65197
8fada74d82be tuned signature;
wenzelm
parents: 65196
diff changeset
   386
        val range = rendering.model.content.doc.range(info.range)
64748
155bf8632104 clarified multiple tooltips;
wenzelm
parents: 64747
diff changeset
   387
        val contents =
65107
70b0113fa4ef clarified pretty margin;
wenzelm
parents: 65093
diff changeset
   388
          info.info.map(t => Protocol.MarkedString(resources.output_pretty_tooltip(List(t))))
64748
155bf8632104 clarified multiple tooltips;
wenzelm
parents: 64747
diff changeset
   389
        (range, contents)
64641
wenzelm
parents: 64623
diff changeset
   390
      }
wenzelm
parents: 64623
diff changeset
   391
    channel.write(Protocol.Hover.reply(id, result))
wenzelm
parents: 64623
diff changeset
   392
  }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   393
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   394
64648
5d7f741aaccb basic support for hyperlinks / Goto Definition Request;
wenzelm
parents: 64646
diff changeset
   395
  /* goto definition */
5d7f741aaccb basic support for hyperlinks / Goto Definition Request;
wenzelm
parents: 64646
diff changeset
   396
64651
ea5620f7b0d8 clarified signature;
wenzelm
parents: 64649
diff changeset
   397
  def goto_definition(id: Protocol.Id, node_pos: Line.Node_Position)
64648
5d7f741aaccb basic support for hyperlinks / Goto Definition Request;
wenzelm
parents: 64646
diff changeset
   398
  {
5d7f741aaccb basic support for hyperlinks / Goto Definition Request;
wenzelm
parents: 64646
diff changeset
   399
    val result =
64651
ea5620f7b0d8 clarified signature;
wenzelm
parents: 64649
diff changeset
   400
      (for ((rendering, offset) <- rendering_offset(node_pos))
64649
d67c3094a0c2 tuned signature -- more explicit types;
wenzelm
parents: 64648
diff changeset
   401
        yield rendering.hyperlinks(Text.Range(offset, offset + 1))) getOrElse Nil
64648
5d7f741aaccb basic support for hyperlinks / Goto Definition Request;
wenzelm
parents: 64646
diff changeset
   402
    channel.write(Protocol.GotoDefinition.reply(id, result))
5d7f741aaccb basic support for hyperlinks / Goto Definition Request;
wenzelm
parents: 64646
diff changeset
   403
  }
5d7f741aaccb basic support for hyperlinks / Goto Definition Request;
wenzelm
parents: 64646
diff changeset
   404
5d7f741aaccb basic support for hyperlinks / Goto Definition Request;
wenzelm
parents: 64646
diff changeset
   405
64767
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   406
  /* document highlights */
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   407
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   408
  def document_highlights(id: Protocol.Id, node_pos: Line.Node_Position)
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   409
  {
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   410
    val result =
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   411
      (for ((rendering, offset) <- rendering_offset(node_pos))
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   412
        yield {
65197
8fada74d82be tuned signature;
wenzelm
parents: 65196
diff changeset
   413
          val model = rendering.model
8fada74d82be tuned signature;
wenzelm
parents: 65196
diff changeset
   414
          rendering.caret_focus_ranges(Text.Range(offset, offset + 1), model.content.text_range)
8fada74d82be tuned signature;
wenzelm
parents: 65196
diff changeset
   415
            .map(r => Protocol.DocumentHighlight.text(model.content.doc.range(r)))
64767
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   416
        }) getOrElse Nil
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   417
    channel.write(Protocol.DocumentHighlights.reply(id, result))
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   418
  }
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   419
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   420
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   421
  /* main loop */
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   422
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   423
  def start()
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   424
  {
64717
d2b50eb3d9ab tuned signature;
wenzelm
parents: 64710
diff changeset
   425
    log("Server started " + Date.now())
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   426
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   427
    def handle(json: JSON.T)
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   428
    {
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   429
      try {
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   430
        json match {
64641
wenzelm
parents: 64623
diff changeset
   431
          case Protocol.Initialize(id) => init(id)
65229
cc96b8c3b8cb explicitly ignore "initialized" message;
wenzelm
parents: 65228
diff changeset
   432
          case Protocol.Initialized(()) =>
64641
wenzelm
parents: 64623
diff changeset
   433
          case Protocol.Shutdown(id) => shutdown(id)
64645
0b513620d949 proper pattern match;
wenzelm
parents: 64644
diff changeset
   434
          case Protocol.Exit(()) => exit()
65162
wenzelm
parents: 65160
diff changeset
   435
          case Protocol.DidOpenTextDocument(file, _, _, text) =>
wenzelm
parents: 65160
diff changeset
   436
            change_document(file, List(Protocol.TextDocumentChange(None, text)))
65160
6e042537555d incremental document changes;
wenzelm
parents: 65134
diff changeset
   437
          case Protocol.DidChangeTextDocument(file, _, changes) => change_document(file, changes)
6e042537555d incremental document changes;
wenzelm
parents: 65134
diff changeset
   438
          case Protocol.DidCloseTextDocument(file) => close_document(file)
64877
31e9920a0dc1 support for semantic completion;
wenzelm
parents: 64870
diff changeset
   439
          case Protocol.Completion(id, node_pos) => completion(id, node_pos)
66138
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   440
          case Protocol.Include_Word(()) => update_dictionary(true, false)
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   441
          case Protocol.Include_Word_Permanently(()) => update_dictionary(true, true)
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   442
          case Protocol.Exclude_Word(()) => update_dictionary(false, false)
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   443
          case Protocol.Exclude_Word_Permanently(()) => update_dictionary(false, true)
f7ef4c50b747 added commands for spell-checker dictionary;
wenzelm
parents: 66101
diff changeset
   444
          case Protocol.Reset_Words(()) => reset_dictionary()
64651
ea5620f7b0d8 clarified signature;
wenzelm
parents: 64649
diff changeset
   445
          case Protocol.Hover(id, node_pos) => hover(id, node_pos)
ea5620f7b0d8 clarified signature;
wenzelm
parents: 64649
diff changeset
   446
          case Protocol.GotoDefinition(id, node_pos) => goto_definition(id, node_pos)
64767
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64755
diff changeset
   447
          case Protocol.DocumentHighlights(id, node_pos) => document_highlights(id, node_pos)
65189
41d2452845fc support for caret handling and dynamic output;
wenzelm
parents: 65184
diff changeset
   448
          case Protocol.Caret_Update(caret) => update_caret(caret)
66098
5aa9cb83e70e clarified modules;
wenzelm
parents: 66096
diff changeset
   449
          case Protocol.State_Init(()) => State_Panel.init(server)
5aa9cb83e70e clarified modules;
wenzelm
parents: 66096
diff changeset
   450
          case Protocol.State_Exit(id) => State_Panel.exit(id)
5aa9cb83e70e clarified modules;
wenzelm
parents: 66096
diff changeset
   451
          case Protocol.State_Locate(id) => State_Panel.locate(id)
5aa9cb83e70e clarified modules;
wenzelm
parents: 66096
diff changeset
   452
          case Protocol.State_Update(id) => State_Panel.update(id)
66211
100c9c997e2b HTML GUI actions via JavaScript;
wenzelm
parents: 66138
diff changeset
   453
          case Protocol.State_Auto_Update(id, enabled) => State_Panel.auto_update(id, enabled)
65983
d8c5603c1732 explicit preview request/response;
wenzelm
parents: 65977
diff changeset
   454
          case Protocol.Preview_Request(file, column) => request_preview(file, column)
66052
39eb61b1fa51 provide information about Isabelle symbols within VSCode;
wenzelm
parents: 65983
diff changeset
   455
          case Protocol.Symbols_Request(()) => channel.write(Protocol.Symbols())
64717
d2b50eb3d9ab tuned signature;
wenzelm
parents: 64710
diff changeset
   456
          case _ => log("### IGNORED")
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   457
        }
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   458
      }
64687
04806ad1e43a clarified protocol errors;
wenzelm
parents: 64684
diff changeset
   459
      catch { case exn: Throwable => channel.log_error_message(Exn.message(exn)) }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   460
    }
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   461
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   462
    @tailrec def loop()
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   463
    {
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   464
      channel.read() match {
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   465
        case Some(json) =>
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   466
          json match {
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   467
            case bulk: List[_] => bulk.foreach(handle(_))
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   468
            case _ => handle(json)
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   469
          }
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   470
          loop()
64717
d2b50eb3d9ab tuned signature;
wenzelm
parents: 64710
diff changeset
   471
        case None => log("### TERMINATE")
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   472
      }
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   473
    }
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   474
    loop()
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   475
  }
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   476
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   477
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   478
  /* abstract editor operations */
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   479
66100
d1ad5a7458c2 proper treatment of editor overlays;
wenzelm
parents: 66098
diff changeset
   480
  object editor extends Server.Editor
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   481
  {
66101
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   482
    /* session */
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   483
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   484
    override def session: Session = server.session
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   485
    override def flush(): Unit = resources.flush_input(session)
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   486
    override def invoke(): Unit = delay_input.invoke()
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   487
66101
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   488
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   489
    /* current situation */
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   490
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   491
    override def current_node(context: Unit): Option[Document.Node.Name] =
66086
3f7067ba5df3 clarified signature;
wenzelm
parents: 66085
diff changeset
   492
      resources.get_caret().map(_.model.node_name)
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   493
    override def current_node_snapshot(context: Unit): Option[Document.Snapshot] =
66086
3f7067ba5df3 clarified signature;
wenzelm
parents: 66085
diff changeset
   494
      resources.get_caret().map(_.model.snapshot())
3f7067ba5df3 clarified signature;
wenzelm
parents: 66085
diff changeset
   495
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   496
    override def node_snapshot(name: Document.Node.Name): Document.Snapshot =
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   497
    {
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   498
      resources.get_model(name) match {
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   499
        case Some(model) => model.snapshot()
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   500
        case None => session.snapshot(name)
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   501
      }
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   502
    }
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   503
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   504
    def current_command(snapshot: Document.Snapshot): Option[Command] =
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   505
    {
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   506
      resources.get_caret() match {
66086
3f7067ba5df3 clarified signature;
wenzelm
parents: 66085
diff changeset
   507
        case Some(caret) => snapshot.current_command(caret.node_name, caret.offset)
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   508
        case None => None
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   509
      }
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   510
    }
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   511
    override def current_command(context: Unit, snapshot: Document.Snapshot): Option[Command] =
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   512
      current_command(snapshot)
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   513
66101
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   514
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   515
    /* overlays */
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   516
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   517
    override def node_overlays(name: Document.Node.Name): Document.Node.Overlays =
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   518
      resources.node_overlays(name)
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   519
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   520
    override def insert_overlay(command: Command, fn: String, args: List[String]): Unit =
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   521
      resources.insert_overlay(command, fn, args)
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   522
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   523
    override def remove_overlay(command: Command, fn: String, args: List[String]): Unit =
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   524
      resources.remove_overlay(command, fn, args)
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   525
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   526
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   527
    /* hyperlinks */
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   528
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   529
    override def hyperlink_command(
66215
9a8b6b86350c proper hyperlink_command, notably for locate_query;
wenzelm
parents: 66211
diff changeset
   530
      focus: Boolean, snapshot: Document.Snapshot, id: Document_ID.Generic,
9a8b6b86350c proper hyperlink_command, notably for locate_query;
wenzelm
parents: 66211
diff changeset
   531
      offset: Symbol.Offset = 0): Option[Hyperlink] =
9a8b6b86350c proper hyperlink_command, notably for locate_query;
wenzelm
parents: 66211
diff changeset
   532
    {
9a8b6b86350c proper hyperlink_command, notably for locate_query;
wenzelm
parents: 66211
diff changeset
   533
      if (snapshot.is_outdated) None
66216
d4949bae0bad clarified editor focus;
wenzelm
parents: 66215
diff changeset
   534
      else
d4949bae0bad clarified editor focus;
wenzelm
parents: 66215
diff changeset
   535
        snapshot.find_command_position(id, offset).map(node_pos =>
d4949bae0bad clarified editor focus;
wenzelm
parents: 66215
diff changeset
   536
          new Hyperlink {
d4949bae0bad clarified editor focus;
wenzelm
parents: 66215
diff changeset
   537
            def follow(unit: Unit) { channel.write(Protocol.Caret_Update(node_pos, focus)) }
d4949bae0bad clarified editor focus;
wenzelm
parents: 66215
diff changeset
   538
          })
66215
9a8b6b86350c proper hyperlink_command, notably for locate_query;
wenzelm
parents: 66211
diff changeset
   539
    }
66094
24658c9d7c78 more general dispatcher operations;
wenzelm
parents: 66086
diff changeset
   540
66101
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   541
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   542
    /* dispatcher thread */
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66100
diff changeset
   543
66094
24658c9d7c78 more general dispatcher operations;
wenzelm
parents: 66086
diff changeset
   544
    override def assert_dispatcher[A](body: => A): A = session.assert_dispatcher(body)
24658c9d7c78 more general dispatcher operations;
wenzelm
parents: 66086
diff changeset
   545
    override def require_dispatcher[A](body: => A): A = session.require_dispatcher(body)
24658c9d7c78 more general dispatcher operations;
wenzelm
parents: 66086
diff changeset
   546
    override def send_dispatcher(body: => Unit): Unit = session.send_dispatcher(body)
24658c9d7c78 more general dispatcher operations;
wenzelm
parents: 66086
diff changeset
   547
    override def send_wait_dispatcher(body: => Unit): Unit = session.send_wait_dispatcher(body)
66085
100f02099532 added abstract editor operations, notably for Query_Operation;
wenzelm
parents: 66054
diff changeset
   548
  }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
   549
}