-
-
Notifications
You must be signed in to change notification settings - Fork 177
/
wrapperWs.ts
91 lines (86 loc) · 3.29 KB
/
wrapperWs.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
// this is required syntax highlighting
import '@codingame/monaco-vscode-json-default-extension';
import { LogLevel } from 'vscode/services';
import { MonacoEditorLanguageClientWrapper, WrapperConfig } from 'monaco-editor-wrapper';
import { configureMonacoWorkers } from '../../common/client/utils.js';
const text = `{
"$schema": "http://json.schemastore.org/coffeelint",
"line_endings": {"value": "unix"}
}`;
export const buildJsonClientUserConfig = (params: {
htmlContainer: HTMLElement
}): WrapperConfig => {
return {
logLevel: LogLevel.Debug,
vscodeApiConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.lightbulb.enabled': 'On',
'editor.wordBasedSuggestions': 'off',
'editor.experimental.asyncTokenization': true
})
}
},
editorAppConfig: {
$type: 'extended',
codeResources: {
main: {
text,
fileExt: 'json'
}
},
useDiffEditor: false,
monacoWorkerFactory: configureMonacoWorkers,
htmlContainer: params.htmlContainer
},
languageClientConfigs: {
json: {
languageId: 'json',
connection: {
options: {
$type: 'WebSocketUrl',
url: 'ws://localhost:30000/sampleServer',
startOptions: {
onCall: () => {
console.log('Connected to socket.');
},
reportStatus: true
},
stopOptions: {
onCall: () => {
console.log('Disconnected from socket.');
},
reportStatus: true
}
}
}
}
}
};
};
export const runJsonWrapper = () => {
const wrapper = new MonacoEditorLanguageClientWrapper();
try {
document.querySelector('#button-start')?.addEventListener('click', async () => {
const config = buildJsonClientUserConfig({
htmlContainer: document.getElementById('monaco-editor-root')!
});
await wrapper.initAndStart(config);
});
document.querySelector('#button-dispose')?.addEventListener('click', async () => {
await wrapper.dispose();
});
} catch (e) {
console.error(e);
}
};