Skip to content

Commit 2f5ee23

Browse files
authored
Add new example Application Playground (#774)
- Integrate views service into new advanced example - Add navigation back to index page - Add missing services, moved re-usable code to the wrapper - Move all styling from HTML to CSS
1 parent bb6d615 commit 2f5ee23

36 files changed

+536
-70
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Click [here](https://www.typefox.io/blog/teaching-the-language-server-protocol-t
2828
- [Groovy Language client and language server example (Location)](#groovy-language-client-and-language-server-example-location)
2929
- [Java Language client and language server example (Location)](#java-language-client-and-language-server-example-location)
3030
- [Cpp / Clangd (Location)](#cpp--clangd-location)
31+
- [Application Playground (Location)](#application-playground-location)
3132
- [Langium grammar DSL (Location)](#langium-grammar-dsl-location)
3233
- [Statemachine DSL (created with Langium) (Location)](#statemachine-dsl-created-with-langium-location)
3334
- [bare monaco-languageclient (Location)](#bare-monaco-languageclient-location)
@@ -141,7 +142,11 @@ Langium examples (here client and server communicate via `vscode-languageserver-
141142

142143
#### Cpp / Clangd ([Location](./packages/examples/src/clangd))
143144

144-
It contains both the [language client](./packages/examples/src/clangd/client/main.ts) and the [langauge server (web worker)](./packages/examples/src/clangd/worker/clangd-server.ts). The clangd language server is compiled to wasm so it can be executed in the browser.
145+
It contains both the [language client](./packages/examples/src/clangd/client/main.ts) and the [langauge server (web worker)](./packages/examples/src/clangd/worker/clangd-server.ts). The clangd language server is compiled to wasm so it can be executed in the browser. <b>Heads up:</b> This is a prototype and still evolving.
146+
147+
#### Application Playground ([Location](./packages/examples/src/appPlayground))
148+
149+
This [example](./packages/examples/src/appPlayground/main.ts) uses the view service provider from `@codingame/monaco-vscode-editor-api` to build an application that utilizes more vscode features. <b>Heads up:</b> This is a prototype and still evolving.
145150

146151
#### Langium grammar DSL ([Location](./packages/examples/src/langium/langium-dsl))
147152

@@ -164,8 +169,6 @@ It demonstrates how a [monaco-editor-wrapper can be combined with a language ser
164169

165170
See [Typescript Language support](./packages/examples/src/ts/wrapperTs.ts).
166171

167-
See [Multi-editor usage](./packages/examples/src/ts/wrapperAdvanced.ts).
168-
169172
#### Server processes
170173

171174
##### JSON Language Server

eslint.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export default [{
3131
'**/lib/**/*',
3232
'**/out/**/*',
3333
'**/bin/**/*',
34-
'**/resources/**/*'
34+
'**/resources/**/*',
35+
'**/production/**/*'
3536
],
3637
}, ...compat.extends('eslint:recommended', 'plugin:@typescript-eslint/recommended'), {
3738
files: [

index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ <h3>Multiple Languageclients</h3>
7878
<a href="./packages/examples/two_langauge_clients.html">Json & Python Languageclients & Language Server (Web Socket)</a>
7979
<br>
8080

81+
<h3>Application Playground</h3>
82+
<a href="./packages/examples/appPlayground.html">Application Playground</a>
83+
8184
<h3>TypeScript</h3>
8285
<a href="./packages/examples/tsExtHost.html">TypeScript Extension Host Worker</a>
8386
<br>

package-lock.json

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

packages/client/CHANGELOG.md

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

55
## [9.0.0-next.5] - 2024-10-23
66

7+
- Function naming adjustments
78
- Prototype: File system endpoint.
89
- Added `createUrl` to `monaco-languageclient/tools`. Moved it here from `monaco-editor-wrapper`.
910
- Updated to eslint 9

packages/client/src/vscode/services.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { LocalizationOptions } from '@codingame/monaco-vscode-localization-
1616
import { EnvironmentOverride } from 'vscode/workbench';
1717
import { Logger } from 'monaco-languageclient/tools';
1818
import { FakeWorker as Worker } from './fakeWorker.js';
19+
import { setUnexpectedErrorHandler } from 'vscode/monaco';
1920

2021
export interface MonacoEnvironmentEnhanced extends monaco.Environment {
2122
vscodeInitialising?: boolean;
@@ -42,7 +43,7 @@ export interface VscodeApiConfig {
4243
export interface InitVscodeApiInstructions extends VscodeApiConfig {
4344
htmlContainer: HTMLElement;
4445
caller?: string;
45-
performChecks?: () => boolean;
46+
performServiceConsistencyChecks?: () => boolean;
4647
logger?: Logger;
4748
}
4849

@@ -127,13 +128,18 @@ export const importAllServices = async (instructions: InitVscodeApiInstructions)
127128

128129
reportServiceLoading(userServices, instructions.logger);
129130

130-
if (instructions.performChecks === undefined || (typeof instructions.performChecks === 'function' && instructions.performChecks())) {
131+
if (instructions.performServiceConsistencyChecks === undefined ||
132+
(typeof instructions.performServiceConsistencyChecks === 'function' && instructions.performServiceConsistencyChecks())) {
131133
if (instructions.viewsConfig?.viewServiceType === 'ViewsService' || instructions.viewsConfig?.viewServiceType === 'WorkspaceService') {
132134
await initialize(userServices, instructions.htmlContainer, instructions.workspaceConfig, instructions.envOptions);
133135
} else {
134136
await initialize(userServices, undefined, instructions.workspaceConfig, instructions.envOptions);
135137
}
136138
}
139+
140+
setUnexpectedErrorHandler((e) => {
141+
instructions.logger?.createErrorAndLog('Unexpected error', e);
142+
});
137143
};
138144

139145
/**

packages/examples/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this npm module are documented in this file.
55
## [2024.10.5] - 2024-10-2x
66

77
- Added clangd example.
8+
- Added application playground example featuring the views service override.
89

910
## [2024.10.4] - 2024-10-23
1011

packages/examples/appPlayground.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>Application Playground</title>
6+
<meta charset="UTF-8" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<link rel="stylesheet" href="style.css">
9+
<link rel="stylesheet" href="./resources/appPlayground/style.css">
10+
</head>
11+
12+
<body>
13+
<div class="exampleHeadelineDiv">
14+
<b class="exampleHeadeline">Application Playground</b> - [<a href="/index.html">Back to Index</a>]
15+
<br>
16+
<b>Heads up:</b> This is a prototype and still evolving.
17+
</div>
18+
<script type="module" rel="modulepreload" src="./src/appPlayground/launcher"></script>
19+
</body>
20+
21+
</html>

packages/examples/bare.html

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

1111

1212
<body>
13-
<h2>JSON Language Client & Language Server (Web Socket)</h2>
13+
<div class="exampleHeadelineDiv">
14+
<b class="exampleHeadeline">JSON Language Client & Language Server (Web Socket)</b> - [<a href="/index.html">Back to Index</a>]
15+
</div>
1416
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
1517
<script type="module">
1618
import { runClient } from "./src/bare/client.ts";

packages/examples/browser.html

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

1111
<body>
12-
<h2>Language Client Pure Browser Example</h2>
12+
<div class="exampleHeadelineDiv">
13+
<b class="exampleHeadeline">Language Client Pure Browser Example</b> - [<a href="/index.html">Back to Index</a>]
14+
</div>
1315
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
1416
<script type="module">
1517
import { runBrowserEditor } from "./src/browser/main.ts";

0 commit comments

Comments
 (0)