author | wenzelm |
Sat, 11 Mar 2017 15:36:47 +0100 | |
changeset 65186 | 4659e87c3795 |
parent 65182 | 973b7669e7d9 |
child 65189 | 41d2452845fc |
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'; |
8 |
import { Decoration } from './decorations' |
|
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 |
||
27 |
/* activate extension */ |
|
28 |
||
64605 | 29 |
export function activate(context: vscode.ExtensionContext) |
30 |
{ |
|
65168 | 31 |
const is_windows = os.type().startsWith("Windows") |
64755 | 32 |
|
65186 | 33 |
const isabelle_home = get_configuration<string>("home") |
34 |
const isabelle_args = get_configuration<Array<string>>("args") |
|
35 |
const cygwin_root = get_configuration<string>("cygwin_root") |
|
64605 | 36 |
|
65182 | 37 |
|
38 |
/* server */ |
|
39 |
||
65172 | 40 |
if (isabelle_home === "") |
64755 | 41 |
vscode.window.showErrorMessage("Missing user settings: isabelle.home") |
64753 | 42 |
else { |
65168 | 43 |
const isabelle_tool = isabelle_home + "/bin/isabelle" |
44 |
const standard_args = ["-o", "vscode_unicode_symbols", "-o", "vscode_pide_extensions"] |
|
65167 | 45 |
|
65168 | 46 |
const server_options: ServerOptions = |
64755 | 47 |
is_windows ? |
65172 | 48 |
{ command: |
49 |
(cygwin_root === "" ? path.join(isabelle_home, "contrib", "cygwin") : cygwin_root) + |
|
50 |
"/bin/bash", |
|
64874
e13ff666af96
enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents:
64833
diff
changeset
|
51 |
args: ["-l", isabelle_tool, "vscode_server"].concat(standard_args, isabelle_args) } : |
64755 | 52 |
{ command: isabelle_tool, |
64874
e13ff666af96
enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents:
64833
diff
changeset
|
53 |
args: ["vscode_server"].concat(standard_args, isabelle_args) }; |
65168 | 54 |
const client_options: LanguageClientOptions = { |
64833 | 55 |
documentSelector: ["isabelle", "isabelle-ml", "bibtex"] |
64753 | 56 |
}; |
64605 | 57 |
|
65168 | 58 |
const client = new LanguageClient("Isabelle", server_options, client_options, false) |
65094 | 59 |
|
65182 | 60 |
|
61 |
/* decorations */ |
|
62 |
||
65094 | 63 |
decorations.init(context) |
65182 | 64 |
vscode.workspace.onDidChangeConfiguration(() => decorations.init(context)) |
65135
158cba86140f
maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents:
65096
diff
changeset
|
65 |
vscode.window.onDidChangeActiveTextEditor(decorations.update_editor) |
158cba86140f
maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents:
65096
diff
changeset
|
66 |
vscode.workspace.onDidCloseTextDocument(decorations.close_document) |
65182 | 67 |
|
65165 | 68 |
client.onReady().then(() => |
69 |
client.onNotification( |
|
70 |
new NotificationType<Decoration, void>("PIDE/decoration"), decorations.apply_decoration)) |
|
65094 | 71 |
|
65182 | 72 |
|
73 |
/* start server */ |
|
74 |
||
65094 | 75 |
context.subscriptions.push(client.start()); |
76 |
} |
|
64605 | 77 |
} |
78 |
||
79 |
export function deactivate() { } |