# HG changeset patch
# User wenzelm
# Date 1496244326 -7200
# Node ID d8c5603c17327dcade187da07f96520def713594
# Parent 5b8fafde7d64526b27a5fbb1e1274f311c439239
explicit preview request/response;
commands, icons, menus like VSCode markdown preview;
clarified Uri information (again);
tuned;
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Pure/build-jars
--- a/src/Pure/build-jars Wed May 31 11:49:29 2017 +0200
+++ b/src/Pure/build-jars Wed May 31 17:25:26 2017 +0200
@@ -167,8 +167,8 @@
../Tools/VSCode/src/channel.scala
../Tools/VSCode/src/document_model.scala
../Tools/VSCode/src/dynamic_output.scala
- ../Tools/VSCode/src/dynamic_preview.scala
../Tools/VSCode/src/grammar.scala
+ ../Tools/VSCode/src/preview.scala
../Tools/VSCode/src/protocol.scala
../Tools/VSCode/src/server.scala
../Tools/VSCode/src/vscode_rendering.scala
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Tools/VSCode/extension/media/Preview.svg
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/VSCode/extension/media/Preview.svg Wed May 31 17:25:26 2017 +0200
@@ -0,0 +1,1 @@
+
\ No newline at end of file
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Tools/VSCode/extension/media/PreviewOnRightPane_16x.svg
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/VSCode/extension/media/PreviewOnRightPane_16x.svg Wed May 31 17:25:26 2017 +0200
@@ -0,0 +1,19 @@
+
+
+
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Tools/VSCode/extension/media/PreviewOnRightPane_16x_dark.svg
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/VSCode/extension/media/PreviewOnRightPane_16x_dark.svg Wed May 31 17:25:26 2017 +0200
@@ -0,0 +1,19 @@
+
+
+
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Tools/VSCode/extension/media/Preview_inverse.svg
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/VSCode/extension/media/Preview_inverse.svg Wed May 31 17:25:26 2017 +0200
@@ -0,0 +1,1 @@
+
\ No newline at end of file
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Tools/VSCode/extension/media/ViewSource.svg
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/VSCode/extension/media/ViewSource.svg Wed May 31 17:25:26 2017 +0200
@@ -0,0 +1,3 @@
+
+]>
\ No newline at end of file
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Tools/VSCode/extension/media/ViewSource_inverse.svg
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/VSCode/extension/media/ViewSource_inverse.svg Wed May 31 17:25:26 2017 +0200
@@ -0,0 +1,1 @@
+
\ No newline at end of file
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Tools/VSCode/extension/package.json
--- a/src/Tools/VSCode/extension/package.json Wed May 31 11:49:29 2017 +0200
+++ b/src/Tools/VSCode/extension/package.json Wed May 31 17:25:26 2017 +0200
@@ -18,16 +18,64 @@
"categories": ["Languages"],
"activationEvents": [
"onLanguage:isabelle",
- "onLanguage:isabelle-ml"
+ "onLanguage:isabelle-ml",
+ "onCommand:isabelle.preview",
+ "onCommand:isabelle.preview-side",
+ "onCommand:isabelle.preview-source"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
- "command": "isabelle.preview",
- "title": "Isabelle Document Preview"
+ "command": "isabelle.preview",
+ "title": "Open Preview",
+ "category": "Isabelle",
+ "icon": {
+ "light": "./media/Preview.svg",
+ "dark": "./media/Preview_inverse.svg"
+ }
+ },
+ {
+ "command": "isabelle.preview-side",
+ "title": "Open Preview to the Side",
+ "category": "Isabelle",
+ "icon": {
+ "light": "./media/PreviewOnRightPane_16x.svg",
+ "dark": "./media/PreviewOnRightPane_16x_dark.svg"
+ }
+ },
+ {
+ "command": "isabelle.preview-source",
+ "title": "Show Source",
+ "category": "Isabelle",
+ "icon": {
+ "light": "./media/ViewSource.svg",
+ "dark": "./media/ViewSource_inverse.svg"
+ }
}
],
+ "menus": {
+ "editor/title": [
+ {
+ "when": "editorLangId == isabelle",
+ "command": "isabelle.preview-side",
+ "alt": "isabelle.preview",
+ "group": "navigation"
+ },
+ {
+ "when": "resourceScheme == isabelle-preview",
+ "command": "isabelle.preview-source",
+ "group": "navigation"
+ }
+ ],
+ "explorer/context": [
+ {
+ "when": "resourceLangId == isabelle",
+ "command": "isabelle.preview",
+ "group": "navigation"
+ }
+ ]
+ },
"languages": [
{
"id": "isabelle",
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Tools/VSCode/extension/src/extension.ts
--- a/src/Tools/VSCode/extension/src/extension.ts Wed May 31 11:49:29 2017 +0200
+++ b/src/Tools/VSCode/extension/src/extension.ts Wed May 31 17:25:26 2017 +0200
@@ -36,11 +36,12 @@
args: ["-l", isabelle_tool, "vscode_server"].concat(standard_args, isabelle_args) } :
{ command: isabelle_tool,
args: ["vscode_server"].concat(standard_args, isabelle_args) };
- const client_options: LanguageClientOptions = {
+ const language_client_options: LanguageClientOptions = {
documentSelector: ["isabelle", "isabelle-ml", "bibtex"]
};
- const client = new LanguageClient("Isabelle", server_options, client_options, false)
+ const language_client =
+ new LanguageClient("Isabelle", server_options, language_client_options, false)
/* decorations */
@@ -52,8 +53,8 @@
window.onDidChangeActiveTextEditor(decorations.update_editor),
workspace.onDidCloseTextDocument(decorations.close_document))
- client.onReady().then(() =>
- client.onNotification(protocol.decoration_type, decorations.apply_decoration))
+ language_client.onReady().then(() =>
+ language_client.onNotification(protocol.decoration_type, decorations.apply_decoration))
/* caret handling */
@@ -70,12 +71,12 @@
}
if (last_caret_update !== caret_update) {
if (caret_update.uri)
- client.sendNotification(protocol.caret_update_type, caret_update)
+ language_client.sendNotification(protocol.caret_update_type, caret_update)
last_caret_update = caret_update
}
}
- client.onReady().then(() =>
+ language_client.onReady().then(() =>
{
context.subscriptions.push(
window.onDidChangeActiveTextEditor(_ => update_caret()),
@@ -91,23 +92,21 @@
dynamic_output.show(true)
dynamic_output.hide()
- client.onReady().then(() =>
+ language_client.onReady().then(() =>
{
- client.onNotification(protocol.dynamic_output_type,
+ language_client.onNotification(protocol.dynamic_output_type,
params => { dynamic_output.clear(); dynamic_output.appendLine(params.content) })
})
- /* dynamic preview */
+ /* preview */
- preview.init(context)
- client.onReady().then(() =>
- client.onNotification(protocol.dynamic_preview_type, params => preview.update(params.content)))
+ language_client.onReady().then(() => preview.init(context, language_client))
/* start server */
- context.subscriptions.push(client.start());
+ context.subscriptions.push(language_client.start());
}
}
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Tools/VSCode/extension/src/library.ts
--- a/src/Tools/VSCode/extension/src/library.ts Wed May 31 11:49:29 2017 +0200
+++ b/src/Tools/VSCode/extension/src/library.ts Wed May 31 17:25:26 2017 +0200
@@ -1,7 +1,7 @@
'use strict';
import * as os from 'os';
-import { ViewColumn, TextEditor, Uri, workspace } from 'vscode'
+import { TextEditor, Uri, workspace } from 'vscode'
/* platform information */
@@ -32,13 +32,3 @@
const config = color + (light ? "_light" : "_dark") + "_color"
return get_configuration(config)
}
-
-
-/* text editor column */
-
-export function other_column(active_editor: TextEditor | null): ViewColumn
-{
- if (!active_editor || active_editor.viewColumn === ViewColumn.Three) return ViewColumn.One
- else if (active_editor.viewColumn === ViewColumn.One) return ViewColumn.Two
- else return ViewColumn.Three
-}
diff -r 5b8fafde7d64 -r d8c5603c1732 src/Tools/VSCode/extension/src/preview.ts
--- a/src/Tools/VSCode/extension/src/preview.ts Wed May 31 11:49:29 2017 +0200
+++ b/src/Tools/VSCode/extension/src/preview.ts Wed May 31 17:25:26 2017 +0200
@@ -1,14 +1,39 @@
'use strict';
import * as timers from 'timers'
-import { TextDocument, TextEditor, TextDocumentContentProvider, ExtensionContext,
- Event, EventEmitter, Uri, Position, workspace, window, commands } from 'vscode'
+import { ViewColumn, TextDocument, TextEditor, TextDocumentContentProvider,
+ ExtensionContext, Event, EventEmitter, Uri, Position, workspace,
+ window, commands } from 'vscode'
+import { LanguageClient } from 'vscode-languageclient';
import * as library from './library'
+import * as protocol from './protocol';
+
+
+/* Uri information */
+
+const preview_uri_template = Uri.parse("isabelle-preview:Preview")
+const preview_uri_scheme = preview_uri_template.scheme
+
+function encode_preview(document_uri: Uri | undefined): Uri | undefined
+{
+ if (document_uri && library.is_file(document_uri)) {
+ return preview_uri_template.with({ query: document_uri.fsPath })
+ }
+ else undefined
+}
+
+function decode_preview(preview_uri: Uri | undefined): Uri | undefined
+{
+ if (preview_uri && preview_uri.scheme === preview_uri_scheme) {
+ return Uri.file(preview_uri.query)
+ }
+ else undefined
+}
/* HTML content */
-const preview_uri = Uri.parse("isabelle-preview:Preview")
+const preview_content = new Map()
const default_preview_content =
`
@@ -20,35 +45,86 @@