src/Tools/VSCode/extension/src/extension.ts
author wenzelm
Thu, 09 Mar 2017 21:25:01 +0100
changeset 65168 9eabc312a2a2
parent 65167 ee569aac344b
child 65171 63655086649f
permissions -rw-r--r--
prefer immutable bindings;
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'
65165
d98ede9e5917 updated to vscode-languageclient 3.0;
wenzelm
parents: 65153
diff changeset
     8
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind, NotificationType }
64605
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
{
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65167
diff changeset
    14
  const is_windows = os.type().startsWith("Windows")
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    15
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65167
diff changeset
    16
  const cygwin_root = vscode.workspace.getConfiguration("isabelle").get<string>("cygwin_root");
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65167
diff changeset
    17
  const isabelle_home = vscode.workspace.getConfiguration("isabelle").get<string>("home");
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65167
diff changeset
    18
  const 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 {
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65167
diff changeset
    25
    const isabelle_tool = isabelle_home + "/bin/isabelle"
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65167
diff changeset
    26
    const standard_args = ["-o", "vscode_unicode_symbols", "-o", "vscode_pide_extensions"]
65167
wenzelm
parents: 65165
diff changeset
    27
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65167
diff changeset
    28
    const server_options: ServerOptions =
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    29
      is_windows ?
65153
wenzelm
parents: 65137
diff changeset
    30
        { command: cygwin_root + "/bin/bash",
64874
e13ff666af96 enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents: 64833
diff changeset
    31
          args: ["-l", isabelle_tool, "vscode_server"].concat(standard_args, isabelle_args) } :
64755
ceb81f4928ea support for Windows;
wenzelm
parents: 64753
diff changeset
    32
        { command: isabelle_tool,
64874
e13ff666af96 enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents: 64833
diff changeset
    33
          args: ["vscode_server"].concat(standard_args, isabelle_args) };
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65167
diff changeset
    34
    const client_options: LanguageClientOptions = {
64833
0f410e3b1d20 support for bibtex entries;
wenzelm
parents: 64756
diff changeset
    35
      documentSelector: ["isabelle", "isabelle-ml", "bibtex"]
64753
79ed396709e4 more robust startup;
wenzelm
parents: 64750
diff changeset
    36
    };
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    37
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65167
diff changeset
    38
    const client = new LanguageClient("Isabelle", server_options, client_options, false)
65094
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    39
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    40
    decorations.init(context)
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65096
diff changeset
    41
    vscode.window.onDidChangeActiveTextEditor(decorations.update_editor)
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65096
diff changeset
    42
    vscode.workspace.onDidCloseTextDocument(decorations.close_document)
65165
d98ede9e5917 updated to vscode-languageclient 3.0;
wenzelm
parents: 65153
diff changeset
    43
    client.onReady().then(() =>
d98ede9e5917 updated to vscode-languageclient 3.0;
wenzelm
parents: 65153
diff changeset
    44
      client.onNotification(
d98ede9e5917 updated to vscode-languageclient 3.0;
wenzelm
parents: 65153
diff changeset
    45
        new NotificationType<Decoration, void>("PIDE/decoration"), decorations.apply_decoration))
65094
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    46
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    47
    context.subscriptions.push(client.start());
386d9d487f62 support for decorations;
wenzelm
parents: 64874
diff changeset
    48
  }
64605
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    49
}
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    50
9c1173a7e4cb basic support for VSCode Language Server protocol;
wenzelm
parents:
diff changeset
    51
export function deactivate() { }