-
Notifications
You must be signed in to change notification settings - Fork 779
/
Copy pathlspInterop.ts
48 lines (37 loc) · 1.27 KB
/
lspInterop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { languages } from 'monaco-editor';
let interop;
export function initializeInterop(self): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
self['BicepInitialize'] = (newInterop) => {
interop = newInterop;
resolve(true);
}
const test = require('../../../Bicep.Wasm/bin/Release/net5.0/wwwroot/_framework/blazor.webassembly.js');
});
}
export function getSemanticTokensLegend(): languages.SemanticTokensLegend {
return interop.invokeMethod('GetSemanticTokensLegend');
}
export function getSemanticTokens(content: string): languages.SemanticTokens {
return interop.invokeMethod('GetSemanticTokens', content);
}
export async function sendLspData(message: string) {
// console.log(message);
return await interop.invokeMethodAsync('SendLspDataAsync', message);
}
export function onLspData(callback: (message: string | Buffer) => void) {
self['ReceiveLspData'] = message => {
// console.log(message);
callback(message);
}
}
export function compile(content: string): string {
return interop.invokeMethod('Compile', content);
}
export function decompile(jsonContent: string): string {
const { bicepFile, error } = interop.invokeMethod('Decompile', jsonContent);
if (error) {
throw error;
}
return bicepFile;
}