author | wenzelm |
Sat, 11 Dec 2021 11:24:48 +0100 | |
changeset 74913 | c2a2be496f35 |
parent 71479 | 6aa2dc263912 |
child 75095 | faa24820fba1 |
permissions | -rw-r--r-- |
66203 | 1 |
'use strict'; |
2 |
||
71479
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
3 |
import { ExtensionContext, Uri, workspace, |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
4 |
window, commands, ViewColumn, WebviewPanel } from 'vscode' |
66203 | 5 |
import { LanguageClient } from 'vscode-languageclient'; |
6 |
import * as library from './library' |
|
7 |
import * as protocol from './protocol' |
|
8 |
||
9 |
||
10 |
let language_client: LanguageClient |
|
11 |
||
71479
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
12 |
class Panel |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
13 |
{ |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
14 |
private webview_panel: WebviewPanel |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
15 |
|
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
16 |
public set_content(title: string, body: string) |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
17 |
{ |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
18 |
this.webview_panel.title = title |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
19 |
this.webview_panel.webview.html = body |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
20 |
} |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
21 |
|
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
22 |
public reveal(column: ViewColumn) |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
23 |
{ |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
24 |
this.webview_panel.reveal(column) |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
25 |
} |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
26 |
|
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
27 |
constructor(column: ViewColumn) |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
28 |
{ |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
29 |
this.webview_panel = |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
30 |
window.createWebviewPanel("isabelle-preview", "Preview", column, |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
31 |
{ |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
32 |
enableScripts: true |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
33 |
}); |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
34 |
this.webview_panel.onDidDispose(() => { panel = null }) |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
35 |
} |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
36 |
} |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
37 |
|
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
38 |
let panel: Panel |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
39 |
|
66203 | 40 |
export function setup(context: ExtensionContext, client: LanguageClient) |
41 |
{ |
|
42 |
language_client = client |
|
43 |
language_client.onNotification(protocol.preview_response_type, params => |
|
44 |
{ |
|
71479
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
45 |
if (!panel) { panel = new Panel(params.column) } |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
46 |
else panel.reveal(params.column) |
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
47 |
panel.set_content(params.label, params.content) |
66203 | 48 |
}) |
49 |
} |
|
50 |
||
51 |
export function request(uri?: Uri, split: boolean = false) |
|
52 |
{ |
|
53 |
const document_uri = uri || window.activeTextEditor.document.uri |
|
71479
6aa2dc263912
less ambitious preview: discontinued preview-update / preview-source which did not work on the spot via WebviewPanel;
wenzelm
parents:
71473
diff
changeset
|
54 |
if (language_client) { |
66203 | 55 |
language_client.sendNotification(protocol.preview_request_type, |
56 |
{ uri: document_uri.toString(), |
|
57 |
column: library.adjacent_editor_column(window.activeTextEditor, split) }) |
|
58 |
} |
|
59 |
} |