forked from TypeFox/monaco-languageclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
73 lines (68 loc) · 2.48 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* --------------------------------------------------------------------------------------------
* 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-groovy-default-extension';
import { LogLevel } from '@codingame/monaco-vscode-api';
import { MonacoEditorLanguageClientWrapper, WrapperConfig } from 'monaco-editor-wrapper';
import { groovyConfig } from '../config.js';
import { configureMonacoWorkers } from '../../common/client/utils.js';
const code = `package test.org;
import java.io.File;
File file = new File("E:/Example.txt");
`;
const wrapperConfig: WrapperConfig = {
$type: 'extended',
htmlContainer: document.getElementById('monaco-editor-root')!,
logLevel: LogLevel.Debug,
vscodeApiConfig: {
serviceOverrides: {
...getKeybindingsServiceOverride(),
},
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.wordBasedSuggestions': 'off',
'editor.experimental.asyncTokenization': true
})
}
},
editorAppConfig: {
codeResources: {
modified: {
text: code,
fileExt: 'groovy'
}
},
monacoWorkerFactory: configureMonacoWorkers
},
languageClientConfigs: {
groovy: {
clientOptions: {
documentSelector: ['groovy']
},
connection: {
options: {
$type: 'WebSocketUrl',
url: `ws://localhost:${groovyConfig.port}${groovyConfig.path}`
}
}
}
}
};
export const runGroovyClient = () => {
const wrapper = new MonacoEditorLanguageClientWrapper();
try {
document.querySelector('#button-start')?.addEventListener('click', async () => {
await wrapper.initAndStart(wrapperConfig);
});
document.querySelector('#button-dispose')?.addEventListener('click', async () => {
await wrapper.dispose();
});
} catch (e) {
console.error(e);
}
};