src/Tools/VSCode/src/server.scala
changeset 64618 c81bd30839a6
parent 64605 9c1173a7e4cb
child 64622 529bbb8977c7
     1.1 --- a/src/Tools/VSCode/src/server.scala	Tue Dec 20 16:08:02 2016 +0100
     1.2 +++ b/src/Tools/VSCode/src/server.scala	Tue Dec 20 17:09:40 2016 +0100
     1.3 @@ -20,21 +20,28 @@
     1.4  {
     1.5    /* Isabelle tool wrapper */
     1.6  
     1.7 +  private val default_text_length = "UTF-16"
     1.8    private lazy val default_logic = Isabelle_System.getenv("ISABELLE_LOGIC")
     1.9  
    1.10    val isabelle_tool = Isabelle_Tool("vscode_server", "VSCode Language Server for PIDE", args =>
    1.11    {
    1.12      var log_file: Option[Path] = None
    1.13 +    var text_length = Length.encoding(default_text_length)
    1.14      var dirs: List[Path] = Nil
    1.15      var logic = default_logic
    1.16      var modes: List[String] = Nil
    1.17      var options = Options.init()
    1.18  
    1.19 +    def text_length_choice: String =
    1.20 +      commas(Length.encodings.map(
    1.21 +        { case (a, _) => if (a == default_text_length) a + " (default)" else a }))
    1.22 +
    1.23      val getopts = Getopts("""
    1.24  Usage: isabelle vscode_server [OPTIONS]
    1.25  
    1.26    Options are:
    1.27      -L FILE      enable logging on FILE
    1.28 +    -T LENGTH    text length encoding: """ + text_length_choice + """
    1.29      -d DIR       include session directory
    1.30      -l NAME      logic session name (default ISABELLE_LOGIC=""" + quote(logic) + """)
    1.31      -m MODE      add print mode for output
    1.32 @@ -43,6 +50,7 @@
    1.33    Run the VSCode Language Server protocol (JSON RPC) over stdin/stdout.
    1.34  """,
    1.35        "L:" -> (arg => log_file = Some(Path.explode(arg))),
    1.36 +      "T:" -> (arg => Length.encoding(arg)),
    1.37        "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))),
    1.38        "l:" -> (arg => logic = arg),
    1.39        "m:" -> (arg => modes = arg :: modes),
    1.40 @@ -56,7 +64,7 @@
    1.41        error("Missing logic image " + quote(logic))
    1.42  
    1.43      val channel = new Channel(System.in, System.out, log_file)
    1.44 -    val server = new Server(channel, options, logic, dirs, modes)
    1.45 +    val server = new Server(channel, options, text_length, logic, dirs, modes)
    1.46  
    1.47      // prevent spurious garbage on the main protocol channel
    1.48      val orig_out = System.out
    1.49 @@ -78,6 +86,7 @@
    1.50  class Server(
    1.51    channel: Channel,
    1.52    options: Options,
    1.53 +  text_length: Length = Length.encoding(Server.default_text_length),
    1.54    session_name: String = Server.default_logic,
    1.55    session_dirs: List[Path] = Nil,
    1.56    modes: List[String] = Nil)
    1.57 @@ -185,12 +194,13 @@
    1.58      for {
    1.59        model <- state.value.models.get(uri)
    1.60        snapshot = model.snapshot()
    1.61 -      offset <- model.doc.offset(pos)
    1.62 +      offset <- model.doc.offset(pos, text_length)
    1.63        info <- tooltip(snapshot, Text.Range(offset, offset + 1))
    1.64      } yield {
    1.65 -      val r = Line.Range(model.doc.position(info.range.start), model.doc.position(info.range.stop))
    1.66 +      val start = model.doc.position(info.range.start, text_length)
    1.67 +      val stop = model.doc.position(info.range.stop, text_length)
    1.68        val s = Pretty.string_of(info.info, margin = tooltip_margin.toDouble)
    1.69 -      (r, List("```\n" + s + "\n```"))
    1.70 +      (Line.Range(start, stop), List("```\n" + s + "\n```"))
    1.71      }
    1.72  
    1.73    private val tooltip_descriptions =