66203
|
1 |
'use strict';
|
|
2 |
|
|
3 |
import * as library from './library'
|
|
4 |
import * as protocol from './protocol'
|
|
5 |
import { Content_Provider } from './content_provider'
|
|
6 |
import { LanguageClient } from 'vscode-languageclient';
|
|
7 |
import { Uri, ExtensionContext, workspace, commands, window } from 'vscode'
|
|
8 |
|
|
9 |
|
|
10 |
/* HTML content */
|
|
11 |
|
|
12 |
const content_provider = new Content_Provider("isabelle-state")
|
|
13 |
|
|
14 |
function encode_state(id: number | undefined): Uri | undefined
|
|
15 |
{
|
|
16 |
return id ? content_provider.uri_template.with({ fragment: id.toString() }) : undefined
|
|
17 |
}
|
|
18 |
|
|
19 |
function decode_state(uri: Uri | undefined): number | undefined
|
|
20 |
{
|
|
21 |
if (uri && uri.scheme === content_provider.uri_scheme) {
|
|
22 |
const id = parseInt(uri.fragment)
|
|
23 |
return id ? id : undefined
|
|
24 |
}
|
|
25 |
else undefined
|
|
26 |
}
|
|
27 |
|
|
28 |
|
|
29 |
/* setup */
|
|
30 |
|
|
31 |
let language_client: LanguageClient
|
|
32 |
|
|
33 |
export function setup(context: ExtensionContext, client: LanguageClient)
|
|
34 |
{
|
|
35 |
context.subscriptions.push(content_provider.register())
|
|
36 |
|
|
37 |
language_client = client
|
|
38 |
language_client.onNotification(protocol.state_output_type, params =>
|
|
39 |
{
|
|
40 |
const uri = encode_state(params.id)
|
|
41 |
if (uri) {
|
|
42 |
content_provider.set_content(uri, params.content)
|
|
43 |
content_provider.update(uri)
|
|
44 |
|
|
45 |
const existing_document =
|
|
46 |
workspace.textDocuments.find(document =>
|
|
47 |
document.uri.scheme === uri.scheme &&
|
|
48 |
document.uri.fragment === uri.fragment)
|
|
49 |
if (!existing_document) {
|
|
50 |
const column = library.adjacent_editor_column(window.activeTextEditor, true)
|
|
51 |
commands.executeCommand("vscode.previewHtml", uri, column, "State")
|
|
52 |
}
|
|
53 |
}
|
|
54 |
})
|
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
/* commands */
|
|
59 |
|
|
60 |
export function init(uri: Uri)
|
|
61 |
{
|
|
62 |
if (language_client) language_client.sendNotification(protocol.state_init_type)
|
|
63 |
}
|
|
64 |
|
|
65 |
export function exit(id: number)
|
|
66 |
{
|
|
67 |
if (language_client) language_client.sendNotification(protocol.state_exit_type, { id: id })
|
|
68 |
}
|
|
69 |
|
66395
|
70 |
export function exit_uri(uri: Uri)
|
|
71 |
{
|
|
72 |
const id = decode_state(uri)
|
|
73 |
if (id) exit(id)
|
|
74 |
}
|
|
75 |
|
66203
|
76 |
export function locate(id: number)
|
|
77 |
{
|
|
78 |
if (language_client) language_client.sendNotification(protocol.state_locate_type, { id: id })
|
|
79 |
}
|
|
80 |
|
|
81 |
export function update(id: number)
|
|
82 |
{
|
|
83 |
if (language_client) language_client.sendNotification(protocol.state_update_type, { id: id })
|
|
84 |
}
|
66211
|
85 |
|
|
86 |
export function auto_update(id: number, enabled: boolean)
|
|
87 |
{
|
|
88 |
if (language_client)
|
|
89 |
language_client.sendNotification(protocol.state_auto_update_type, { id: id, enabled: enabled })
|
|
90 |
}
|