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