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