author | wenzelm |
Sun, 12 Mar 2017 18:45:53 +0100 | |
changeset 65201 | 2d01b30e6ac6 |
parent 65200 | 1227a68fac7a |
child 65202 | 187277b77d50 |
permissions | -rw-r--r-- |
64605 | 1 |
'use strict'; |
2 |
||
3 |
import * as vscode from 'vscode'; |
|
4 |
import * as path from 'path'; |
|
65172 | 5 |
import * as fs from 'fs'; |
64755 | 6 |
import * as os from 'os'; |
65094 | 7 |
import * as decorations from './decorations'; |
65201 | 8 |
import * as protocol from './protocol'; |
65165 | 9 |
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind, NotificationType } |
64605 | 10 |
from 'vscode-languageclient'; |
11 |
||
12 |
||
65180 | 13 |
/* Isabelle configuration */ |
14 |
||
65186 | 15 |
export function get_configuration<T>(name: string): T |
65180 | 16 |
{ |
65186 | 17 |
return vscode.workspace.getConfiguration("isabelle").get<T>(name) |
65180 | 18 |
} |
19 |
||
20 |
export function get_color(color: string, light: boolean): string |
|
21 |
{ |
|
22 |
const config = color + (light ? "_light" : "_dark") + "_color" |
|
65186 | 23 |
return get_configuration<string>(config) |
65180 | 24 |
} |
25 |
||
26 |
||
65201 | 27 |
/* activate extension */ |
65200
1227a68fac7a
more explicit message type: allows body to become empty;
wenzelm
parents:
65191
diff
changeset
|
28 |
|
65201 | 29 |
let last_caret_update: protocol.Caret_Update = {} |
65180 | 30 |
|
64605 | 31 |
export function activate(context: vscode.ExtensionContext) |
32 |
{ |
|
65168 | 33 |
const is_windows = os.type().startsWith("Windows") |
64755 | 34 |
|
65186 | 35 |
const isabelle_home = get_configuration<string>("home") |
36 |
const isabelle_args = get_configuration<Array<string>>("args") |
|
37 |
const cygwin_root = get_configuration<string>("cygwin_root") |
|
64605 | 38 |
|
65182 | 39 |
|
40 |
/* server */ |
|
41 |
||
65172 | 42 |
if (isabelle_home === "") |
64755 | 43 |
vscode.window.showErrorMessage("Missing user settings: isabelle.home") |
64753 | 44 |
else { |
65168 | 45 |
const isabelle_tool = isabelle_home + "/bin/isabelle" |
46 |
const standard_args = ["-o", "vscode_unicode_symbols", "-o", "vscode_pide_extensions"] |
|
65167 | 47 |
|
65168 | 48 |
const server_options: ServerOptions = |
64755 | 49 |
is_windows ? |
65172 | 50 |
{ command: |
51 |
(cygwin_root === "" ? path.join(isabelle_home, "contrib", "cygwin") : cygwin_root) + |
|
52 |
"/bin/bash", |
|
64874
e13ff666af96
enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents:
64833
diff
changeset
|
53 |
args: ["-l", isabelle_tool, "vscode_server"].concat(standard_args, isabelle_args) } : |
64755 | 54 |
{ command: isabelle_tool, |
64874
e13ff666af96
enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents:
64833
diff
changeset
|
55 |
args: ["vscode_server"].concat(standard_args, isabelle_args) }; |
65168 | 56 |
const client_options: LanguageClientOptions = { |
64833 | 57 |
documentSelector: ["isabelle", "isabelle-ml", "bibtex"] |
64753 | 58 |
}; |
64605 | 59 |
|
65168 | 60 |
const client = new LanguageClient("Isabelle", server_options, client_options, false) |
65094 | 61 |
|
65182 | 62 |
|
65201 | 63 |
/* decorations */ |
64 |
||
65 |
decorations.init(context) |
|
66 |
vscode.workspace.onDidChangeConfiguration(() => decorations.init(context)) |
|
67 |
vscode.window.onDidChangeActiveTextEditor(decorations.update_editor) |
|
68 |
vscode.workspace.onDidCloseTextDocument(decorations.close_document) |
|
69 |
||
70 |
client.onReady().then(() => |
|
71 |
client.onNotification(protocol.decoration_type, decorations.apply_decoration)) |
|
72 |
||
73 |
||
65189 | 74 |
/* caret handling and dynamic output */ |
75 |
||
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
65189
diff
changeset
|
76 |
const dynamic_output = vscode.window.createOutputChannel("Isabelle Output") |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
65189
diff
changeset
|
77 |
context.subscriptions.push(dynamic_output) |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
65189
diff
changeset
|
78 |
dynamic_output.show(true) |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
65189
diff
changeset
|
79 |
dynamic_output.hide() |
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
65189
diff
changeset
|
80 |
|
65189 | 81 |
function update_caret() |
82 |
{ |
|
83 |
const editor = vscode.window.activeTextEditor |
|
65201 | 84 |
let caret_update: protocol.Caret_Update = {} |
65189 | 85 |
if (editor) { |
86 |
const uri = editor.document.uri |
|
87 |
const cursor = editor.selection.active |
|
88 |
if (uri.scheme === "file" && cursor) |
|
89 |
caret_update = { uri: uri.toString(), line: cursor.line, character: cursor.character } |
|
90 |
} |
|
91 |
if (last_caret_update !== caret_update) { |
|
65201 | 92 |
client.sendNotification(protocol.caret_update_type, caret_update) |
65189 | 93 |
last_caret_update = caret_update |
94 |
} |
|
95 |
} |
|
96 |
||
97 |
client.onReady().then(() => |
|
98 |
{ |
|
65201 | 99 |
client.onNotification(protocol.dynamic_output_type, |
65200
1227a68fac7a
more explicit message type: allows body to become empty;
wenzelm
parents:
65191
diff
changeset
|
100 |
params => { dynamic_output.clear(); dynamic_output.appendLine(params.body) }) |
65189 | 101 |
vscode.window.onDidChangeActiveTextEditor(_ => update_caret()) |
102 |
vscode.window.onDidChangeTextEditorSelection(_ => update_caret()) |
|
103 |
update_caret() |
|
104 |
}) |
|
105 |
||
106 |
||
65182 | 107 |
/* start server */ |
108 |
||
65094 | 109 |
context.subscriptions.push(client.start()); |
110 |
} |
|
64605 | 111 |
} |
112 |
||
113 |
export function deactivate() { } |