Skip to content

Commit 207baec

Browse files
committed
Align example execution. Only use basic javascript/typescript support for now
1 parent 10cf6f1 commit 207baec

29 files changed

+182
-166
lines changed

Diff for: index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ <h3>Python language client and language server</h3>
3939
<a href="./packages/examples/python.html">Client for Python Pyright Language Server</a><br>
4040

4141
<h3>Groovy language client and language server</h3>
42-
Requires docker. Please execute <b><code>docker-compose -f ./packages/examples/resources/groovy/docker-compose.yml up -d</code></b> beforehand:<br>
42+
Requires docker. Please execute <b><code>docker compose -f ./packages/examples/resources/groovy/docker-compose.yml up -d</code></b> beforehand:<br>
4343
<a href="./packages/examples/groovy.html">Client for Groovy Language Server</a>
4444

4545
<h2>Monaco Editor React</h2>

Diff for: package-lock.json

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/examples/browser.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
<h2>Monaco Language Client Browser Sample</h2>
1313
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
1414
<script type="module">
15-
import { startBrowserEditor } from "./src/browser/main.ts";
16-
startBrowserEditor();
15+
import { configureMonacoWorkers, runBrowserEditor } from "./src/browser/main.ts";
16+
17+
configureMonacoWorkers();
18+
runBrowserEditor();
1719
</script>
1820
</body>
1921
</html>

Diff for: packages/examples/client.html

-19
This file was deleted.

Diff for: packages/examples/groovy.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ <h2>Monaco Language Client Groovy Sample</h2>
1313
<button type="button" id="button-dispose">Dispose</button>
1414
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
1515
<script type="module">
16-
import { startGroovyClient } from "./src/groovy/client/main.ts";
17-
startGroovyClient();
16+
import { configureMonacoWorkers, runGroovyClient } from "./src/groovy/client/main.ts";
17+
18+
configureMonacoWorkers();
19+
runGroovyClient();
1820
</script>
1921
</body>
2022

Diff for: packages/examples/package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"@codingame/monaco-vscode-textmate-service-override": "~3.1.0",
6767
"@codingame/monaco-vscode-theme-defaults-default-extension": "~3.1.0",
6868
"@codingame/monaco-vscode-theme-service-override": "~3.1.0",
69+
"@codingame/monaco-vscode-javascript-default-extension": "~3.1.0",
6970
"@codingame/monaco-vscode-typescript-basics-default-extension": "~3.1.0",
7071
"@codingame/monaco-vscode-typescript-language-features-default-extension": "~3.1.0",
7172
"@codingame/monaco-vscode-language-pack-de": "~3.1.0",
@@ -112,12 +113,10 @@
112113
"clean": "shx rm -fr dist *.tsbuildinfo",
113114
"compile": "tsc --build tsconfig.src.json",
114115
"build:msg": "echo Building main examples:",
115-
"build:worker:vite": "vite --config vite.statemachine-worker.ts build",
116-
"build:worker:statemachine": "esbuild ./src/langium/statemachine/worker/statemachine-server.js --bundle --tree-shaking=true --minify --format=iife --outfile=./dist/worker/statemachineServerWorker.js",
117-
"build": "npm run build:msg && npm run clean && npm run compile && npm run build:worker:statemachine",
116+
"build": "npm run build:msg && npm run clean && npm run compile",
118117
"start:server:json": "node --loader ts-node/esm src/json/server/direct.ts",
119118
"start:server:python": "node --loader ts-node/esm src/python/server/direct.ts",
120119
"start:server:groovy": "node --watch --loader ts-node/esm src/groovy/server/direct.ts",
121120
"langium:generate": "langium generate --file ./src/langium/statemachine/config/langium-config.json"
122121
}
123-
}
122+
}

Diff for: packages/examples/python.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ <h2>Monaco Language Client Python Example</h2>
1313
<button type="button" id="button-dispose">Dispose</button>
1414
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
1515
<script type="module">
16-
import { startPythonClient } from "./src/python/client/main.ts";
17-
startPythonClient();
16+
import { configureMonacoWorkers, runPythonWrapper } from "./src/python/client/main.ts";
17+
18+
configureMonacoWorkers();
19+
runPythonWrapper();
1820
</script>
1921
</body>
2022

Diff for: packages/examples/react_python.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010
<body>
1111
<div id="root"></div>
12-
<script type="module" src="./src/python/client/reactPython.tsx"></script>
12+
<script type="module">
13+
import { configureMonacoWorkers, runPythonReact } from './src/python/client/reactPython.tsx';
14+
15+
configureMonacoWorkers();
16+
runPythonReact();
17+
</script>
1318
</body>
1419

1520
</html>

Diff for: packages/examples/react_statemachine.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010
<body>
1111
<div id="root"></div>
12-
<script type="module" src="./src/langium/statemachine/main-react.tsx"></script>
12+
<script type="module">
13+
import { configureMonacoWorkers, runStatemachineReact } from './src/langium/statemachine/main-react.tsx';
14+
15+
configureMonacoWorkers();
16+
runStatemachineReact();
17+
</script>
1318
</body>
1419

1520
</html>

Diff for: packages/examples/src/browser/main.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import { createUrl } from 'monaco-editor-wrapper';
2222
import { CloseAction, ErrorAction, MessageTransports } from 'vscode-languageclient';
2323
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';
2424

25-
useWorkerFactory({
26-
basePath: '../../../node_modules'
27-
});
25+
export const configureMonacoWorkers = () => {
26+
useWorkerFactory({
27+
basePath: '../../../node_modules'
28+
});
29+
};
2830

2931
const codeConverter = createCodeConverter();
3032
const protocolConverter = createProtocolConverter(undefined, true, true);
@@ -184,7 +186,7 @@ export const createJsonEditor = async (config: {
184186
});
185187
};
186188

187-
export const startBrowserEditor = async () => {
189+
export const runBrowserEditor = async () => {
188190
let mainVscodeDocument: vscode.TextDocument | undefined;
189191
const languageId = 'json';
190192

Diff for: packages/examples/src/groovy/client/main.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import { UserConfig } from 'monaco-editor-wrapper';
1111
import { groovyConfig } from '../config.js';
1212
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';
1313

14-
useWorkerFactory({
15-
basePath: '../../../node_modules'
16-
});
14+
export const configureMonacoWorkers = () => {
15+
useWorkerFactory({
16+
basePath: '../../../node_modules'
17+
});
18+
};
1719

18-
const languageId = 'groovy';
1920
const code = `package test.org;
2021
import java.io.File ;
2122
File file = new File("E:/Example.txt");
@@ -31,7 +32,7 @@ const userConfig: UserConfig = {
3132
},
3233
editorAppConfig: {
3334
$type: 'extended',
34-
languageId: languageId,
35+
languageId: 'groovy',
3536
code,
3637
useDiffEditor: false,
3738
userConfiguration: {
@@ -50,7 +51,7 @@ const userConfig: UserConfig = {
5051
}
5152
};
5253

53-
export const startGroovyClient = () => {
54+
export const runGroovyClient = () => {
5455
try {
5556
const htmlElement = document.getElementById('monaco-editor-root');
5657
document.querySelector('#button-start')?.addEventListener('click', () => {

Diff for: packages/examples/src/json/client/wrapperWs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const jsonClientUserConfig: UserConfig = {
7272
}
7373
};
7474

75-
export const executeJsonClient = () => {
75+
export const runJsonWrapper = () => {
7676
try {
7777
const htmlElement = document.getElementById('monaco-editor-root');
7878
document.querySelector('#button-start')?.addEventListener('click', () => {

Diff for: packages/examples/src/langium/langium-dsl/wrapperLangium.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import { setupLangiumClientExtended } from './config/extendedConfig.js';
88
import { setupLangiumClientClassic } from './config/classicConfig.js';
99
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';
1010

11-
useWorkerFactory({
12-
basePath: '../../../node_modules'
13-
});
14-
1511
let wrapper: MonacoEditorLanguageClientWrapper | undefined;
1612
let extended = false;
17-
1813
const htmlElement = document.getElementById('monaco-editor-root');
19-
export const run = async () => {
14+
15+
export const configureMonacoWorkers = () => {
16+
useWorkerFactory({
17+
basePath: '../../../node_modules'
18+
});
19+
};
20+
21+
export const runLangiumDslWrapper = async () => {
2022
try {
2123
document.querySelector('#button-start-classic')?.addEventListener('click', startLangiumClientClassic);
2224
document.querySelector('#button-start-extended')?.addEventListener('click', startLangiumClientExtended);

Diff for: packages/examples/src/langium/statemachine/main-react.tsx

+20-20
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ import { createLangiumGlobalConfig } from './config/wrapperStatemachineConfig.js
1010
import { loadStatemachinWorkerRegular } from './main.js';
1111
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';
1212

13-
useWorkerFactory({
14-
basePath: '../../../node_modules'
15-
});
13+
export const configureMonacoWorkers = () => {
14+
useWorkerFactory({
15+
basePath: '../../../node_modules'
16+
});
17+
};
1618

17-
const startEditor = async () => {
18-
const langiumGlobalConfig = await createLangiumGlobalConfig(loadStatemachinWorkerRegular());
19-
const comp = <MonacoEditorReactComp
20-
userConfig={langiumGlobalConfig}
21-
style={{
22-
'paddingTop': '5px',
23-
'height': '80vh'
24-
}}
25-
/>;
19+
export const runStatemachineReact = async () => {
20+
try {
21+
const langiumGlobalConfig = await createLangiumGlobalConfig(loadStatemachinWorkerRegular());
22+
const comp = <MonacoEditorReactComp
23+
userConfig={langiumGlobalConfig}
24+
style={{
25+
'paddingTop': '5px',
26+
'height': '80vh'
27+
}}
28+
/>;
2629

27-
const root = ReactDOM.createRoot(document.getElementById('root')!);
28-
root.render(comp);
30+
const root = ReactDOM.createRoot(document.getElementById('root')!);
31+
root.render(comp);
32+
} catch (e) {
33+
console.error(e);
34+
}
2935
};
30-
31-
try {
32-
startEditor();
33-
} catch (e) {
34-
console.error(e);
35-
}

Diff for: packages/examples/src/langium/statemachine/main.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { MonacoEditorLanguageClientWrapper } from 'monaco-editor-wrapper';
88
import { createLangiumGlobalConfig } from './config/wrapperStatemachineConfig.js';
99
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';
1010

11-
useWorkerFactory({
12-
basePath: '../../../node_modules'
13-
});
14-
1511
const wrapper = new MonacoEditorLanguageClientWrapper();
1612
const wrapper2 = new MonacoEditorLanguageClientWrapper();
1713

14+
export const configureMonacoWorkers = () => {
15+
useWorkerFactory({
16+
basePath: '../../../node_modules'
17+
});
18+
};
19+
1820
const startEditor = async () => {
1921
if (wrapper.isStarted() && wrapper2.isStarted()) {
2022
alert('Editor was already started!');
@@ -55,7 +57,7 @@ const disposeEditor = async () => {
5557
console.log(wrapper2.reportStatus().join('\n'));
5658
};
5759

58-
export const run = async () => {
60+
export const runStatemachineWrapper = async () => {
5961
try {
6062
document.querySelector('#button-start')?.addEventListener('click', startEditor);
6163
document.querySelector('#button-dispose')?.addEventListener('click', disposeEditor);

Diff for: packages/examples/src/python/client/main.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import { RegisteredFileSystemProvider, registerFileSystemOverlay, RegisteredMemo
1111
import { createUserConfig } from './config.js';
1212
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';
1313

14-
useWorkerFactory({
15-
basePath: '../../../node_modules'
16-
});
14+
export const configureMonacoWorkers = () => {
15+
useWorkerFactory({
16+
basePath: '../../../node_modules'
17+
});
18+
};
1719

18-
export const startPythonClient = () => {
20+
export const runPythonWrapper = () => {
1921
const code = 'print("Hello, World!")';
2022
const fileSystemProvider = new RegisteredFileSystemProvider(false);
2123
fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/workspace/hello.py'), code));

Diff for: packages/examples/src/python/client/reactPython.tsx

+25-21
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,32 @@ import { MonacoEditorReactComp } from '@typefox/monaco-editor-react';
99
import { createUserConfig } from './config.js';
1010
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';
1111

12-
useWorkerFactory({
13-
basePath: '../../../node_modules'
14-
});
12+
export const configureMonacoWorkers = () => {
13+
useWorkerFactory({
14+
basePath: '../../../node_modules'
15+
});
16+
};
1517

16-
/**
17-
* Code is intentionally incorrect - language server will pick this up on connection and highlight the error
18-
*/
19-
const code = `def main():
20-
return pass`;
18+
export const runPythonReact = () => {
19+
/**
20+
* Code is intentionally incorrect - language server will pick this up on connection and highlight the error
21+
*/
22+
const code = `def main():
23+
return pass`;
2124

22-
const onTextChanged = (text: string, isDirty: boolean) => {
23-
console.log(`Dirty? ${isDirty} Content: ${text}`);
24-
};
25+
const onTextChanged = (text: string, isDirty: boolean) => {
26+
console.log(`Dirty? ${isDirty} Content: ${text}`);
27+
};
2528

26-
const comp = <MonacoEditorReactComp
27-
userConfig={createUserConfig(code)}
28-
style={{
29-
'paddingTop': '5px',
30-
'height': '80vh'
31-
}}
32-
onTextChanged={onTextChanged}
33-
/>;
29+
const comp = <MonacoEditorReactComp
30+
userConfig={createUserConfig(code)}
31+
style={{
32+
'paddingTop': '5px',
33+
'height': '80vh'
34+
}}
35+
onTextChanged={onTextChanged}
36+
/>;
3437

35-
const root = ReactDOM.createRoot(document.getElementById('root')!);
36-
root.render(comp);
38+
const root = ReactDOM.createRoot(document.getElementById('root')!);
39+
root.render(comp);
40+
};

0 commit comments

Comments
 (0)