forked from TypeFox/monaco-languageclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
51 lines (44 loc) · 1.79 KB
/
main.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
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox GmbH (http://www.typefox.io). All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import { createMonacoEditor, createUrl, doInit, initWebSocketAndStartClient } from '../../common/client-commons.js';
export const startJsonClient = async () => {
// use the same common method to create a monaco editor for json
await performInit(true);
await createJsonEditor({
htmlElement: document.getElementById('container')!,
content: createDefaultJsonContent()
});
const url = createUrl('localhost', 30000, '/sampleServer');
createWebSocketAndStartClient(url);
};
/** backwards compatible wrapper for legacy version, only support json as languageId */
export const createWebSocketAndStartClient = (url: string): WebSocket => {
return initWebSocketAndStartClient(url, 'json');
};
export const createDefaultJsonContent = (): string => {
return `{
"$schema": "http://json.schemastore.org/coffeelint",
"line_endings": "unix"
}`;
};
/* backwards compatible wrapper for legacy version, for json lang only */
export const performInit = async (vscodeApiInit: boolean) => {
return doInit(vscodeApiInit, {
id: 'json',
extensions: ['.json', '.jsonc'],
aliases: ['JSON', 'json'],
mimetypes: ['application/json']
});
};
export const createJsonEditor = async (config: {
htmlElement: HTMLElement,
content: string
}) => {
return createMonacoEditor({
htmlElement: config.htmlElement,
content: config.content,
languageId: 'json'
});
};