author | wenzelm |
Mon, 12 Jun 2017 15:52:49 +0200 | |
changeset 66072 | fd26cf23e9b2 |
parent 66070 | 65a68dcd95c3 |
child 66096 | 6187612e83c1 |
permissions | -rw-r--r-- |
64605 | 1 |
'use strict'; |
2 |
||
3 |
import * as path from 'path'; |
|
65172 | 4 |
import * as fs from 'fs'; |
65968 | 5 |
import * as library from './library' |
65094 | 6 |
import * as decorations from './decorations'; |
65958 | 7 |
import * as preview from './preview'; |
65201 | 8 |
import * as protocol from './protocol'; |
66052
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65987
diff
changeset
|
9 |
import * as symbol from './symbol'; |
66060
b2bfbefd354f
symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
66052
diff
changeset
|
10 |
import * as completion from './completion'; |
b2bfbefd354f
symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
66052
diff
changeset
|
11 |
import { ExtensionContext, workspace, window, commands, languages } from 'vscode'; |
65165 | 12 |
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind, NotificationType } |
64605 | 13 |
from 'vscode-languageclient'; |
14 |
||
15 |
||
65201 | 16 |
let last_caret_update: protocol.Caret_Update = {} |
65180 | 17 |
|
65969 | 18 |
export function activate(context: ExtensionContext) |
64605 | 19 |
{ |
65968 | 20 |
const isabelle_home = library.get_configuration<string>("home") |
21 |
const isabelle_args = library.get_configuration<Array<string>>("args") |
|
22 |
const cygwin_root = library.get_configuration<string>("cygwin_root") |
|
64605 | 23 |
|
65182 | 24 |
|
25 |
/* server */ |
|
26 |
||
65172 | 27 |
if (isabelle_home === "") |
65969 | 28 |
window.showErrorMessage("Missing user settings: isabelle.home") |
64753 | 29 |
else { |
65168 | 30 |
const isabelle_tool = isabelle_home + "/bin/isabelle" |
31 |
const standard_args = ["-o", "vscode_unicode_symbols", "-o", "vscode_pide_extensions"] |
|
65167 | 32 |
|
65168 | 33 |
const server_options: ServerOptions = |
65970 | 34 |
library.platform_is_windows() ? |
65172 | 35 |
{ command: |
36 |
(cygwin_root === "" ? path.join(isabelle_home, "contrib", "cygwin") : cygwin_root) + |
|
37 |
"/bin/bash", |
|
64874
e13ff666af96
enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents:
64833
diff
changeset
|
38 |
args: ["-l", isabelle_tool, "vscode_server"].concat(standard_args, isabelle_args) } : |
64755 | 39 |
{ command: isabelle_tool, |
64874
e13ff666af96
enable vscode_unicode_symbols by default, despite asymmetry of input and output;
wenzelm
parents:
64833
diff
changeset
|
40 |
args: ["vscode_server"].concat(standard_args, isabelle_args) }; |
65983 | 41 |
const language_client_options: LanguageClientOptions = { |
64833 | 42 |
documentSelector: ["isabelle", "isabelle-ml", "bibtex"] |
64753 | 43 |
}; |
64605 | 44 |
|
65983 | 45 |
const language_client = |
46 |
new LanguageClient("Isabelle", server_options, language_client_options, false) |
|
65094 | 47 |
|
65182 | 48 |
|
65201 | 49 |
/* decorations */ |
50 |
||
51 |
decorations.init(context) |
|
65975 | 52 |
context.subscriptions.push( |
53 |
workspace.onDidChangeConfiguration(() => decorations.init(context)), |
|
54 |
workspace.onDidChangeTextDocument(event => decorations.touch_document(event.document)), |
|
55 |
window.onDidChangeActiveTextEditor(decorations.update_editor), |
|
56 |
workspace.onDidCloseTextDocument(decorations.close_document)) |
|
65201 | 57 |
|
65983 | 58 |
language_client.onReady().then(() => |
59 |
language_client.onNotification(protocol.decoration_type, decorations.apply_decoration)) |
|
65201 | 60 |
|
61 |
||
65978 | 62 |
/* caret handling */ |
65191
4c9c83311cad
dynamic output, depending on caret focus (see also Tools/jEdit/src/output_dockable.scala);
wenzelm
parents:
65189
diff
changeset
|
63 |
|
65189 | 64 |
function update_caret() |
65 |
{ |
|
65969 | 66 |
const editor = window.activeTextEditor |
65201 | 67 |
let caret_update: protocol.Caret_Update = {} |
65189 | 68 |
if (editor) { |
69 |
const uri = editor.document.uri |
|
70 |
const cursor = editor.selection.active |
|
65972 | 71 |
if (library.is_file(uri) && cursor) |
65189 | 72 |
caret_update = { uri: uri.toString(), line: cursor.line, character: cursor.character } |
73 |
} |
|
74 |
if (last_caret_update !== caret_update) { |
|
65202 | 75 |
if (caret_update.uri) |
65983 | 76 |
language_client.sendNotification(protocol.caret_update_type, caret_update) |
65189 | 77 |
last_caret_update = caret_update |
78 |
} |
|
79 |
} |
|
80 |
||
65983 | 81 |
language_client.onReady().then(() => |
65189 | 82 |
{ |
65975 | 83 |
context.subscriptions.push( |
84 |
window.onDidChangeActiveTextEditor(_ => update_caret()), |
|
85 |
window.onDidChangeTextEditorSelection(_ => update_caret())) |
|
65189 | 86 |
update_caret() |
87 |
}) |
|
88 |
||
89 |
||
65978 | 90 |
/* dynamic output */ |
91 |
||
92 |
const dynamic_output = window.createOutputChannel("Isabelle Output") |
|
93 |
context.subscriptions.push(dynamic_output) |
|
94 |
dynamic_output.show(true) |
|
95 |
dynamic_output.hide() |
|
96 |
||
65983 | 97 |
language_client.onReady().then(() => |
65978 | 98 |
{ |
65983 | 99 |
language_client.onNotification(protocol.dynamic_output_type, |
65979 | 100 |
params => { dynamic_output.clear(); dynamic_output.appendLine(params.content) }) |
65978 | 101 |
}) |
102 |
||
103 |
||
65983 | 104 |
/* preview */ |
65958 | 105 |
|
65984
8e6a833da7db
register commands earlier, before prover startup;
wenzelm
parents:
65983
diff
changeset
|
106 |
context.subscriptions.push( |
65987 | 107 |
commands.registerCommand("isabelle.preview", uri => preview.request(uri, false)), |
108 |
commands.registerCommand("isabelle.preview-split", uri => preview.request(uri, true)), |
|
109 |
commands.registerCommand("isabelle.preview-source", preview.source), |
|
110 |
commands.registerCommand("isabelle.preview-update", preview.update)) |
|
65984
8e6a833da7db
register commands earlier, before prover startup;
wenzelm
parents:
65983
diff
changeset
|
111 |
|
65983 | 112 |
language_client.onReady().then(() => preview.init(context, language_client)) |
65958 | 113 |
|
114 |
||
66052
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65987
diff
changeset
|
115 |
/* Isabelle symbols */ |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65987
diff
changeset
|
116 |
|
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65987
diff
changeset
|
117 |
language_client.onReady().then(() => |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65987
diff
changeset
|
118 |
{ |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65987
diff
changeset
|
119 |
language_client.onNotification(protocol.symbols_type, |
66070
65a68dcd95c3
dynamic configuration of prettify-symbols-mode, similar to VSCoq;
wenzelm
parents:
66063
diff
changeset
|
120 |
params => symbol.init(context, params.entries)) |
66052
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65987
diff
changeset
|
121 |
language_client.sendNotification(protocol.symbols_request_type) |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65987
diff
changeset
|
122 |
}) |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65987
diff
changeset
|
123 |
|
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65987
diff
changeset
|
124 |
|
66060
b2bfbefd354f
symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
66052
diff
changeset
|
125 |
/* completion */ |
b2bfbefd354f
symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
66052
diff
changeset
|
126 |
|
b2bfbefd354f
symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
66052
diff
changeset
|
127 |
const completion_provider = new completion.Completion_Provider |
b2bfbefd354f
symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
66052
diff
changeset
|
128 |
for (const mode of ["isabelle", "isabelle-ml"]) { |
b2bfbefd354f
symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
66052
diff
changeset
|
129 |
context.subscriptions.push( |
b2bfbefd354f
symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
66052
diff
changeset
|
130 |
languages.registerCompletionItemProvider(mode, completion_provider)) |
b2bfbefd354f
symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
66052
diff
changeset
|
131 |
} |
b2bfbefd354f
symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
66052
diff
changeset
|
132 |
|
65182 | 133 |
/* start server */ |
134 |
||
65986 | 135 |
context.subscriptions.push(language_client.start()) |
65094 | 136 |
} |
64605 | 137 |
} |
138 |
||
139 |
export function deactivate() { } |