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