forked from TypeFox/monaco-languageclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapperWs.ts
88 lines (83 loc) · 3.25 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
/* --------------------------------------------------------------------------------------------
* 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 '@codingame/monaco-vscode-api';
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 = (htmlContainer?: HTMLElement): WrapperConfig => {
return {
$type: 'extended',
htmlContainer,
logLevel: LogLevel.Debug,
vscodeApiConfig: {
serviceOverrides: {
...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: {
codeResources: {
modified: {
text,
fileExt: 'json'
}
},
monacoWorkerFactory: configureMonacoWorkers
},
languageClientConfigs: {
json: {
clientOptions: {
documentSelector: ['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(document.getElementById('monaco-editor-root')!);
await wrapper.initAndStart(config);
});
document.querySelector('#button-dispose')?.addEventListener('click', async () => {
await wrapper.dispose();
});
} catch (e) {
console.error(e);
}
};