src/Tools/VSCode/extension/src/extension.ts
author wenzelm
Fri, 03 Mar 2017 19:33:52 +0100
changeset 65094 386d9d487f62
parent 64874 e13ff666af96
child 65096 27d376c33c02
permissions -rw-r--r--
support for decorations;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     1
'use strict';
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     2
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     3
import * as vscode from 'vscode';
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     4
import * as path from 'path';
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
     5
import * as os from 'os';
65094
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
     6
import * as decorations from './decorations';
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
     7
import { Decoration } from './decorations'
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     8
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind }
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
     9
  from 'vscode-languageclient';
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
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    12
export function activate(context: vscode.ExtensionContext)
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    13
{
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    14
  let is_windows = os.type().startsWith("Windows")
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    15
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    16
  let cygwin_root = vscode.workspace.getConfiguration("isabelle").get<string>("cygwin_root");
64734
12558536d977 more configuration;
wenzelm
parents: 64605
diff changeset
    17
  let isabelle_home = vscode.workspace.getConfiguration("isabelle").get<string>("home");
64743
wenzelm
parents: 64735
diff changeset
    18
  let isabelle_args = vscode.workspace.getConfiguration("isabelle").get<Array<string>>("args");
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    19
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    20
  if (is_windows && cygwin_root == "")
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    21
    vscode.window.showErrorMessage("Missing user settings: isabelle.cygwin_root")
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    22
  else if (isabelle_home == "")
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    23
    vscode.window.showErrorMessage("Missing user settings: isabelle.home")
64753
79ed396709e4 more robust startup;
wenzelm
parents: 64750
diff changeset
    24
  else {
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    25
    let isabelle_tool = isabelle_home.concat("/bin/isabelle")
64874
e13ff666af96 enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents: 64833
diff changeset
    26
    let standard_args = ["-o", "vscode_unicode_symbols"]
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    27
    let run =
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    28
      is_windows ?
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    29
        { command: cygwin_root.concat("/bin/bash"),
64874
e13ff666af96 enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents: 64833
diff changeset
    30
          args: ["-l", isabelle_tool, "vscode_server"].concat(standard_args, isabelle_args) } :
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    31
        { command: isabelle_tool,
64874
e13ff666af96 enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents: 64833
diff changeset
    32
          args: ["vscode_server"].concat(standard_args, isabelle_args) };
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    33
64756
3cc892bd8f0f avoid hardwired options: use isabelle.args settings instead;
wenzelm
parents: 64755
diff changeset
    34
    let server_options: ServerOptions = { run: run, debug: run };
64753
79ed396709e4 more robust startup;
wenzelm
parents: 64750
diff changeset
    35
    let client_options: LanguageClientOptions = {
64833
0f410e3b1d20 support for bibtex entries;
wenzelm
parents: 64756
diff changeset
    36
      documentSelector: ["isabelle", "isabelle-ml", "bibtex"]
64753
79ed396709e4 more robust startup;
wenzelm
parents: 64750
diff changeset
    37
    };
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    38
65094
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    39
    let client = new LanguageClient("Isabelle", server_options, client_options, false)
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    40
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    41
    decorations.init(context)
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    42
    client.onNotification<Decoration>({method: "PIDE/decoration"},
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    43
      function (decoration: Decoration) { return decorations.apply(decoration) })
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    44
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    45
    context.subscriptions.push(client.start());
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    46
  }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    47
}
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    48
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    49
export function deactivate() { }