Skip to content

Commit e7a2a44

Browse files
committed
WIP: Unify examples, disabled currently broken exmaples for now. Updated to monaco-vscode-api 2.0.2
1 parent f2e01d9 commit e7a2a44

32 files changed

+646
-512
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"name": "Chrome",
2727
"type": "chrome",
2828
"request": "launch",
29-
"url": "http://localhost:8080",
29+
"url": "http://localhost:20001",
3030
"webRoot": "${workspaceFolder}"
3131
}
3232
]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ With v7 we decided to use readily treemended version of monaco-editor called [@c
9191

9292
```yaml
9393
"overrides": {
94-
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.0"
94+
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.2"
9595
},
9696
"resolutions": {
97-
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.0"
97+
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.2"
9898
}
9999
```
100100

@@ -336,7 +336,7 @@ loader.config({ monaco });
336336
If you use pnpm, you have to add `vscode` / `@codingame/monaco-vscode-api` as direct dependency (see the [following table](#monaco-editor--codingamemonaco-vscode-api-compatibility-table)), otherwise the installation will fail.
337337

338338
```json
339-
"vscode": "npm:@codingame/monaco-vscode-api@~2.0.0"
339+
"vscode": "npm:@codingame/monaco-vscode-api@~2.0.2"
340340
```
341341

342342
## Monaco-editor / @codingame/monaco-vscode-api compatibility table

docs/versions-and-history.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The following table describes which version of **monaco-languageclient** and **@
66

77
| monaco-languageclient | monaco-vscode-api | monaco-vscode-editor-api | monaco-editor | release date | comment |
88
| :---- | :---- | :--- | :--- | :--- | :--- |
9-
| 8.0.0 | 2.0.0 | 2.0.0 | 0.45.0 | 2024-02-0x | `@codingame/monaco-vscode-editor-api` replaces `@codingame/monaco-editor-treemended` |
9+
| 8.0.0 | 2.0.1 | 2.0.1 | 0.45.0 | 2024-02-0x | `@codingame/monaco-vscode-editor-api` replaces `@codingame/monaco-editor-treemended` |
1010
| 7.3.0 | 1.85.0 | 1.85.0 | 0.45.0 | 2024-01-04 | |
1111
| 7.2.0 | 1.83.16 | 1.83.16 | 0.44.0 | 2023-12-07 | |
1212
| 7.1.0 | 1.83.12 | 1.83.12 | 0.44.0 | 2023-11-27 | |

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ <h3>JSON language client and language server</h3>
2121
<a href="packages/examples/client.html">Client for Node.js Language Server</a>
2222
<h3>Python language client and language server</h3>
2323
Please execute <b><code>npm run start:example:server:python</code></b> beforehand:<br>
24-
<a href="packages/examples/python.html">Client for Python Pyright Language Server</a>
24+
<a href="packages/examples/python.html">Client for Python Pyright Language Server</a><br>
25+
<a href="packages/examples/react_python.html">React client for Python Pyright Language Server</a>
2526
<h3>Groovy language client and language server</h3>
2627
Requires docker. Please execute <b><code>docker-compose -f ./packages/examples/resources/groovy/docker-compose.yml up -d</code></b> beforehand:<br>
2728
<a href="packages/examples/groovy.html">Client for Groovy Language Server</a>

package-lock.json

Lines changed: 273 additions & 226 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,7 @@
1818
"typescript": "~5.3.3",
1919
"vite": "~5.0.12",
2020
"vitest": "~1.2.1",
21-
"webdriverio": "~8.29.1"
22-
},
23-
"overrides": {
24-
"@types/shelljs": {
25-
"glob": "npm:glob@>=7.0.0 <8.0.0"
26-
},
27-
"@types/glob": {
28-
"@types/minimatch": "npm:@types/minimatch@>=3.0.0 <4.0.0"
29-
},
30-
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.0"
31-
},
32-
"resolutions": {
33-
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.0"
21+
"webdriverio": "~8.29.7"
3422
},
3523
"volta": {
3624
"node": "20.11.0",

packages/client/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this npm module are documented in this file.
44

55
## [8.0.0] - 2024-02-0x
66

7-
- Updated to `@codingame/[email protected].0`. This ensures amoung other things proper sematic versioning
7+
- Updated to `@codingame/[email protected].1`. This ensures amoung other things proper sematic versioning
88
- Details
99
- WIP: Repository now includes `monaco-editor-wrapper` and `@typefox/monaco-editor-react`
1010

packages/client/package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@
4848
"License.txt"
4949
],
5050
"dependencies": {
51-
"@codingame/monaco-vscode-editor-service-override": "~2.0.0",
52-
"@codingame/monaco-vscode-languages-service-override": "~2.0.0",
53-
"@codingame/monaco-vscode-model-service-override": "~2.0.0",
54-
"@codingame/monaco-vscode-api": "~2.0.0",
55-
"@codingame/monaco-vscode-editor-api": "~2.0.0",
56-
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.0",
57-
"vscode": "npm:@codingame/monaco-vscode-api@~2.0.0",
51+
"@codingame/monaco-vscode-editor-service-override": "~2.0.2",
52+
"@codingame/monaco-vscode-languages-service-override": "~2.0.2",
53+
"@codingame/monaco-vscode-model-service-override": "~2.0.2",
54+
"@codingame/monaco-vscode-api": "~2.0.2",
55+
"@codingame/monaco-vscode-editor-api": "~2.0.2",
56+
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.2",
57+
"vscode": "npm:@codingame/monaco-vscode-api@~2.0.2",
5858
"vscode-languageclient": "~9.0.1"
5959
},
6060
"peerDependencies": {
61-
"@codingame/monaco-vscode-api": "~2.0.0",
62-
"@codingame/monaco-vscode-editor-api": "~2.0.0",
63-
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.0",
64-
"vscode": "npm:@codingame/monaco-vscode-api@~2.0.0"
61+
"@codingame/monaco-vscode-api": "~2.0.2",
62+
"@codingame/monaco-vscode-editor-api": "~2.0.2",
63+
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.2",
64+
"vscode": "npm:@codingame/monaco-vscode-api@~2.0.2"
6565
},
6666
"peerDependenciesMeta": {
6767
"@codingame/monaco-vscode-api": {
@@ -78,10 +78,10 @@
7878
}
7979
},
8080
"overrides": {
81-
"monaco-editor": "$@codingame/monaco-vscode-editor-api"
81+
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.2"
8282
},
8383
"resolutions": {
84-
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.0"
84+
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.2"
8585
},
8686
"scripts": {
8787
"clean": "shx rm -fr lib *.tsbuildinfo",

packages/client/tsconfig.src.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"compilerOptions": {
44
"rootDir": "src",
55
"outDir": "lib",
6-
"declarationDir": "lib"
6+
"declarationDir": "lib",
7+
"types": [
8+
"vscode"
9+
]
710
},
811
"include": [
912
"src/**/*.ts",

packages/examples/package.json

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,33 @@
4343
}
4444
},
4545
"dependencies": {
46-
"@codingame/monaco-vscode-api": "~2.0.0",
47-
"@codingame/monaco-vscode-editor-api": "~2.0.0",
48-
"@codingame/monaco-vscode-configuration-service-override": "~2.0.0",
49-
"@codingame/monaco-vscode-editor-service-override": "~2.0.0",
50-
"@codingame/monaco-vscode-files-service-override": "~2.0.0",
51-
"@codingame/monaco-vscode-groovy-default-extension": "~2.0.0",
52-
"@codingame/monaco-vscode-json-default-extension": "~2.0.0",
53-
"@codingame/monaco-vscode-keybindings-service-override": "~2.0.0",
54-
"@codingame/monaco-vscode-python-default-extension": "~2.0.0",
55-
"@codingame/monaco-vscode-textmate-service-override": "~2.0.0",
56-
"@codingame/monaco-vscode-theme-defaults-default-extension": "~2.0.0",
57-
"@codingame/monaco-vscode-theme-service-override": "~2.0.0",
58-
"@codingame/monaco-vscode-language-pack-de": "~2.0.0",
59-
"@codingame/monaco-vscode-language-pack-es": "~2.0.0",
60-
"@codingame/monaco-vscode-language-pack-fr": "~2.0.0",
46+
"@codingame/monaco-vscode-api": "~2.0.2",
47+
"@codingame/monaco-vscode-editor-api": "~2.0.2",
48+
"@codingame/monaco-vscode-configuration-service-override": "~2.0.2",
49+
"@codingame/monaco-vscode-editor-service-override": "~2.0.2",
50+
"@codingame/monaco-vscode-files-service-override": "~2.0.2",
51+
"@codingame/monaco-vscode-groovy-default-extension": "~2.0.2",
52+
"@codingame/monaco-vscode-json-default-extension": "~2.0.2",
53+
"@codingame/monaco-vscode-keybindings-service-override": "~2.0.2",
54+
"@codingame/monaco-vscode-python-default-extension": "~2.0.2",
55+
"@codingame/monaco-vscode-textmate-service-override": "~2.0.2",
56+
"@codingame/monaco-vscode-theme-defaults-default-extension": "~2.0.2",
57+
"@codingame/monaco-vscode-theme-service-override": "~2.0.2",
58+
"@codingame/monaco-vscode-language-pack-de": "~2.0.2",
59+
"@codingame/monaco-vscode-language-pack-es": "~2.0.2",
60+
"@codingame/monaco-vscode-language-pack-fr": "~2.0.2",
61+
"@typefox/monaco-editor-react": "~3.0.0-next.0",
6162
"express": "~4.18.2",
6263
"langium": "~2.1.0",
6364
"langium-statemachine-dsl": "~2.1.0",
64-
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.0",
65+
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.2",
6566
"monaco-languageclient": "~8.0.0-next.0",
67+
"monaco-editor-wrapper": "~4.0.0-next.0",
6668
"pyright": "~1.1.348",
6769
"react": "~18.2.0",
6870
"react-dom": "~18.2.0",
6971
"request-light": "~0.7.0",
70-
"vscode": "npm:@codingame/monaco-vscode-api@~2.0.0",
72+
"vscode": "npm:@codingame/monaco-vscode-api@~2.0.2",
7173
"vscode-json-languageservice": "~5.3.7",
7274
"vscode-languageclient": "~9.0.1",
7375
"vscode-languageserver": "~9.0.1",
@@ -77,8 +79,8 @@
7779
},
7880
"devDependencies": {
7981
"@types/express": "~4.17.21",
80-
"@types/node": "~20.11.5",
81-
"@types/react": "~18.2.48",
82+
"@types/node": "~20.11.16",
83+
"@types/react": "~18.2.52",
8284
"@types/react-dom": "~18.2.18",
8385
"@types/ws": "~8.5.10",
8486
"ts-node": "~10.9.1",
@@ -88,7 +90,7 @@
8890
"monaco-editor": "$@codingame/monaco-vscode-editor-api"
8991
},
9092
"resolutions": {
91-
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.0"
93+
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~2.0.2"
9294
},
9395
"volta": {
9496
"node": "20.11.0",

packages/examples/python.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
<body>
1111
<h2>Monaco Language Client Python Example</h2>
12-
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
12+
<button type="button" id="button-start">Start</button>
13+
<button type="button" id="button-dispose">Dispose</button>
14+
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
1315
<script type="module">
1416
import { startPythonClient } from "./src/python/client/main.ts";
1517
startPythonClient();

packages/examples/react_python.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Monaco Editor React Component Python</title>
8+
</head>
9+
10+
<body>
11+
<div id="root"></div>
12+
<script type="module" src="./src/python/client/reactPython.tsx"></script>
13+
</body>
14+
15+
</html>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/* --------------------------------------------------------------------------------------------
2+
* Copyright (c) 2024 TypeFox GmbH (http://www.typefox.io). All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
* ------------------------------------------------------------------------------------------ */
5+
6+
import { ModelUpdate, MonacoEditorLanguageClientWrapper, UserConfig } from 'monaco-editor-wrapper';
7+
import { languages } from 'monaco-editor';
8+
9+
const wrapper = new MonacoEditorLanguageClientWrapper();
10+
11+
export const startEditor = async (userConfig: UserConfig, htmlElement: HTMLElement | null, code: string, codeOriginal?: string) => {
12+
if (wrapper.isStarted()) {
13+
console.warn('Editor was already started!');
14+
} else {
15+
configureCodeEditors(userConfig, code, codeOriginal);
16+
toggleSwapDiffButton(true);
17+
await restartEditor(userConfig, htmlElement);
18+
}
19+
};
20+
21+
export const getWrapper = () => {
22+
return wrapper;
23+
};
24+
25+
export const updateModel = async (modelUpdate: ModelUpdate) => {
26+
if (wrapper.getMonacoEditorApp()?.getConfig().useDiffEditor) {
27+
await wrapper.updateDiffModel(modelUpdate);
28+
} else {
29+
await wrapper.updateModel(modelUpdate);
30+
}
31+
};
32+
33+
export const swapEditors = async (userConfig: UserConfig, htmlElement: HTMLElement | null, code: string, codeOriginal?: string) => {
34+
userConfig.wrapperConfig.editorAppConfig.useDiffEditor = !userConfig.wrapperConfig.editorAppConfig.useDiffEditor;
35+
saveMainCode(!userConfig.wrapperConfig.editorAppConfig.useDiffEditor);
36+
configureCodeEditors(userConfig, code, codeOriginal);
37+
await restartEditor(userConfig, htmlElement);
38+
};
39+
40+
export const disposeEditor = async (useDiffEditor: boolean) => {
41+
wrapper.reportStatus();
42+
toggleSwapDiffButton(false);
43+
const codeMain = saveMainCode(useDiffEditor);
44+
45+
await wrapper.dispose();
46+
return codeMain;
47+
};
48+
49+
const restartEditor = async (userConfig: UserConfig, htmlElement: HTMLElement | null) => {
50+
await wrapper.dispose();
51+
await wrapper.initAndStart(userConfig, htmlElement);
52+
logEditorInfo(userConfig);
53+
};
54+
55+
const configureCodeEditors = (userConfig: UserConfig, code: string, codeOriginal?: string) => {
56+
if (userConfig.wrapperConfig.editorAppConfig.useDiffEditor) {
57+
userConfig.wrapperConfig.editorAppConfig.code = code;
58+
userConfig.wrapperConfig.editorAppConfig.codeOriginal = codeOriginal;
59+
} else {
60+
userConfig.wrapperConfig.editorAppConfig.code = code;
61+
}
62+
};
63+
64+
const saveMainCode = (saveFromDiff: boolean) => {
65+
if (saveFromDiff) {
66+
return wrapper.getModel(true)!.getValue();
67+
} else {
68+
return wrapper.getModel()!.getValue();
69+
}
70+
};
71+
72+
const toggleSwapDiffButton = (enabled: boolean) => {
73+
const button = document.getElementById('button-swap') as HTMLButtonElement;
74+
if (button !== null) {
75+
button.disabled = !enabled;
76+
}
77+
};
78+
79+
const logEditorInfo = (userConfig: UserConfig) => {
80+
console.log(`# of configured languages: ${languages.getLanguages().length}`);
81+
console.log(`Main code: ${wrapper.getModel(true)?.getValue() ?? ''}`);
82+
if (userConfig.wrapperConfig.editorAppConfig.useDiffEditor) {
83+
console.log(`Modified code: ${wrapper.getModel()!.getValue()}`);
84+
}
85+
};
86+
87+
export const getTextContent = async (url: URL) => {
88+
const response = await fetch(url.href);
89+
return response.text();
90+
};

packages/examples/src/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
* ------------------------------------------------------------------------------------------ */
55
/* client side export only */
6-
export * from './common/client-commons.js';
7-
export * from './common/language-client-runner.js';
8-
export * from './browser/main.js';
9-
export * from './json/client/main.js';
10-
export * from './langium/statemachineClient.js';
6+
// temporary disabled
7+
// export * from './browser/main.js';
8+
export * from './python/client/config.js';
119
export * from './python/client/main.js';
12-
export * from './react/app.js';
13-
export * from './react/main.js';
10+
export * from './python/client/reactPython.js';

0 commit comments

Comments
 (0)