Skip to content

Commit

Permalink
Add new example Application Playground (#774)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
kaisalmen authored Oct 29, 2024
1 parent bb6d615 commit 2f5ee23
Show file tree
Hide file tree
Showing 36 changed files with 536 additions and 70 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Click [here](https://www.typefox.io/blog/teaching-the-language-server-protocol-t
- [Groovy Language client and language server example (Location)](#groovy-language-client-and-language-server-example-location)
- [Java Language client and language server example (Location)](#java-language-client-and-language-server-example-location)
- [Cpp / Clangd (Location)](#cpp--clangd-location)
- [Application Playground (Location)](#application-playground-location)
- [Langium grammar DSL (Location)](#langium-grammar-dsl-location)
- [Statemachine DSL (created with Langium) (Location)](#statemachine-dsl-created-with-langium-location)
- [bare monaco-languageclient (Location)](#bare-monaco-languageclient-location)
Expand Down Expand Up @@ -141,7 +142,11 @@ Langium examples (here client and server communicate via `vscode-languageserver-

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

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.
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.

#### Application Playground ([Location](./packages/examples/src/appPlayground))

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.

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

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

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

See [Multi-editor usage](./packages/examples/src/ts/wrapperAdvanced.ts).

#### Server processes

##### JSON Language Server
Expand Down
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export default [{
'**/lib/**/*',
'**/out/**/*',
'**/bin/**/*',
'**/resources/**/*'
'**/resources/**/*',
'**/production/**/*'
],
}, ...compat.extends('eslint:recommended', 'plugin:@typescript-eslint/recommended'), {
files: [
Expand Down
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ <h3>Multiple Languageclients</h3>
<a href="./packages/examples/two_langauge_clients.html">Json & Python Languageclients & Language Server (Web Socket)</a>
<br>

<h3>Application Playground</h3>
<a href="./packages/examples/appPlayground.html">Application Playground</a>

<h3>TypeScript</h3>
<a href="./packages/examples/tsExtHost.html">TypeScript Extension Host Worker</a>
<br>
Expand Down
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this npm module are documented in this file.

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

- Function naming adjustments
- Prototype: File system endpoint.
- Added `createUrl` to `monaco-languageclient/tools`. Moved it here from `monaco-editor-wrapper`.
- Updated to eslint 9
Expand Down
10 changes: 8 additions & 2 deletions packages/client/src/vscode/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { LocalizationOptions } from '@codingame/monaco-vscode-localization-
import { EnvironmentOverride } from 'vscode/workbench';
import { Logger } from 'monaco-languageclient/tools';
import { FakeWorker as Worker } from './fakeWorker.js';
import { setUnexpectedErrorHandler } from 'vscode/monaco';

export interface MonacoEnvironmentEnhanced extends monaco.Environment {
vscodeInitialising?: boolean;
Expand All @@ -42,7 +43,7 @@ export interface VscodeApiConfig {
export interface InitVscodeApiInstructions extends VscodeApiConfig {
htmlContainer: HTMLElement;
caller?: string;
performChecks?: () => boolean;
performServiceConsistencyChecks?: () => boolean;
logger?: Logger;
}

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

reportServiceLoading(userServices, instructions.logger);

if (instructions.performChecks === undefined || (typeof instructions.performChecks === 'function' && instructions.performChecks())) {
if (instructions.performServiceConsistencyChecks === undefined ||
(typeof instructions.performServiceConsistencyChecks === 'function' && instructions.performServiceConsistencyChecks())) {
if (instructions.viewsConfig?.viewServiceType === 'ViewsService' || instructions.viewsConfig?.viewServiceType === 'WorkspaceService') {
await initialize(userServices, instructions.htmlContainer, instructions.workspaceConfig, instructions.envOptions);
} else {
await initialize(userServices, undefined, instructions.workspaceConfig, instructions.envOptions);
}
}

setUnexpectedErrorHandler((e) => {
instructions.logger?.createErrorAndLog('Unexpected error', e);
});
};

/**
Expand Down
1 change: 1 addition & 0 deletions packages/examples/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this npm module are documented in this file.
## [2024.10.5] - 2024-10-2x

- Added clangd example.
- Added application playground example featuring the views service override.

## [2024.10.4] - 2024-10-23

Expand Down
21 changes: 21 additions & 0 deletions packages/examples/appPlayground.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>Application Playground</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="./resources/appPlayground/style.css">
</head>

<body>
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">Application Playground</b> - [<a href="/index.html">Back to Index</a>]
<br>
<b>Heads up:</b> This is a prototype and still evolving.
</div>
<script type="module" rel="modulepreload" src="./src/appPlayground/launcher"></script>
</body>

</html>
4 changes: 3 additions & 1 deletion packages/examples/bare.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@


<body>
<h2>JSON Language Client & Language Server (Web Socket)</h2>
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">JSON Language Client & Language Server (Web Socket)</b> - [<a href="/index.html">Back to Index</a>]
</div>
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
<script type="module">
import { runClient } from "./src/bare/client.ts";
Expand Down
4 changes: 3 additions & 1 deletion packages/examples/browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
</head>

<body>
<h2>Language Client Pure Browser Example</h2>
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">Language Client Pure Browser Example</b> - [<a href="/index.html">Back to Index</a>]
</div>
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
<script type="module">
import { runBrowserEditor } from "./src/browser/main.ts";
Expand Down
10 changes: 6 additions & 4 deletions packages/examples/clangd.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
</head>

<body>
<h2>Cpp Language Client & Clangd Language Server (Worker/Wasm)</h2>
<b>Heads up:</b> This is a prototype and still evolving.<br>
The clangd language server worker has been derived from: <a href="https://github.com/guyutongxue/clangd-in-browser">clangd-in-browser</a><br>
<button type="button" id="button-start">Start</button>
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">Cpp Language Client & Clangd Language Server (Worker/Wasm)</b> - [<a href="/index.html">Back to Index</a>]
<br>
<b>Heads up:</b> This is a prototype and still evolving.<br>
The clangd language server worker has been derived from: <a href="https://github.com/guyutongxue/clangd-in-browser">clangd-in-browser</a><br>
<button type="button" id="button-start">Start</button> </div>
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
<label for="openFiles">Select open file:</label>
<select name="openFiles" id="openFiles">
Expand Down
9 changes: 6 additions & 3 deletions packages/examples/eclipse.jdt.ls.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
</head>

<body>
<h2>Java Language Client & Language Server (Web Socket)</h2>
<button type="button" id="button-start">Start</button>
<button type="button" id="button-dispose">Dispose</button>
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">Java Language Client & Language Server (Web Socket)</b> - [<a href="/index.html">Back to Index</a>]
<br>
<button type="button" id="button-start">Start</button>
<button type="button" id="button-dispose">Dispose</button>
</div>
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
<script type="module">
import { runEclipseJdtLsClient } from "./src/eclipse.jdt.ls/client/main.ts";
Expand Down
9 changes: 6 additions & 3 deletions packages/examples/groovy.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
</head>

<body>
<h2>Groovy Language Client & Language Server (Web Socket)</h2>
<button type="button" id="button-start">Start</button>
<button type="button" id="button-dispose">Dispose</button>
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">Groovy Language Client & Language Server (Web Socket)</b> - [<a href="/index.html">Back to Index</a>]
<br>
<button type="button" id="button-start">Start</button>
<button type="button" id="button-dispose">Dispose</button>
</div>
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
<script type="module">
import { runGroovyClient } from "./src/groovy/client/main.ts";
Expand Down
4 changes: 4 additions & 0 deletions packages/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ <h3>Cpp / Clangd</h3>
<a href="./clangd.html">Cpp Language Client & Clangd Language Server (Worker/Wasm)</a>
<br>

<h3>Application Playground</h3>
<a href="./appPlayground.html">Application Playground</a>
<br>

<h3>JSON</h3>
<a href="./browser.html">Language Client Pure Browser Example</a>
<br>
Expand Down
9 changes: 6 additions & 3 deletions packages/examples/json.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
</head>

<body>
<h2>JSON Language Client & Language Server (Web Socket)</h2>
<button type="button" id="button-start">Start</button>
<button type="button" id="button-dispose">Dispose</button>
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">JSON Language Client & Language Server (Web Socket)</b> - [<a href="/index.html">Back to Index</a>]
<br>
<button type="button" id="button-start">Start</button>
<button type="button" id="button-dispose">Dispose</button>
</div>
<div id="monaco-editor-root" style="height: 80vh;"></div>
<script type="module">
import { runJsonWrapper } from './src/json/client/wrapperWs.ts';
Expand Down
5 changes: 3 additions & 2 deletions packages/examples/langium.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
</head>

<body>
<h2>Langium Grammar DSL Language Client & Language Server (Worker)</h2>
<div style="padding: 0px 5px 5px 0px">
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">Langium Grammar DSL Language Client & Language Server (Worker)</b> - [<a href="/index.html">Back to Index</a>]
<br>
<button type="button" id="button-start-classic">Start Classic</button>
<button type="button" id="button-start-extended">Start Extended</button>
<button type="button" id="button-dispose">Dispose</button>
Expand Down
5 changes: 5 additions & 0 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"dependencies": {
"@codingame/monaco-vscode-configuration-service-override": "~10.1.1",
"@codingame/monaco-vscode-cpp-default-extension": "~10.1.1",
"@codingame/monaco-vscode-explorer-service-override": "~10.1.1",
"@codingame/monaco-vscode-files-service-override": "~10.1.1",
"@codingame/monaco-vscode-groovy-default-extension": "~10.1.1",
"@codingame/monaco-vscode-keybindings-service-override": "~10.1.1",
Expand All @@ -73,6 +74,10 @@
"@codingame/monaco-vscode-theme-service-override": "~10.1.1",
"@codingame/monaco-vscode-typescript-basics-default-extension": "~10.1.1",
"@codingame/monaco-vscode-typescript-language-features-default-extension": "~10.1.1",
"@codingame/monaco-vscode-views-service-override": "~10.1.1",
"@codingame/monaco-vscode-remote-agent-service-override": "~10.1.1",
"@codingame/monaco-vscode-environment-service-override": "~10.1.1",
"@codingame/monaco-vscode-secret-storage-service-override": "~10.1.1",
"@typefox/monaco-editor-react": "~6.0.0-next.5",
"cors": "^2.8.5",
"express": "~4.21.1",
Expand Down
9 changes: 6 additions & 3 deletions packages/examples/python.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
</head>

<body>
<h2>Python Language Client & Pyright Language Server (Web Socket)</h2>
<button type="button" id="button-start">Start</button>
<button type="button" id="button-dispose">Dispose</button>
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">Python Language Client & Pyright Language Server (Web Socket)</b> - [<a href="/index.html">Back to Index</a>]
<br>
<button type="button" id="button-start">Start</button>
<button type="button" id="button-dispose">Dispose</button>
</div>
<div id="monaco-editor-root" style="width:800px;height:600px;border:1px solid grey"></div>
<script type="module">
import { runPythonWrapper } from "./src/python/client/main.ts";
Expand Down
11 changes: 7 additions & 4 deletions packages/examples/react_python.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
</head>

<body>
<h2>React: Python Language Client & Language Server (Web Socket)</h2>
<button type="button" id="button-start">Start</button>
<label>Enable Strict mode:</label><input type="checkbox" id="checkbox-strictmode" />
<button type="button" id="button-dispose">Dispose</button>
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">React: Python Language Client & Language Server (Web Socket)</b> - [<a href="/index.html">Back to Index</a>]
<br>
<button type="button" id="button-start">Start</button>
<label>Enable Strict mode:</label><input type="checkbox" id="checkbox-strictmode" />
<button type="button" id="button-dispose">Dispose</button>
</div>
<div id="monaco-editor-root"></div>
<script type="module">
import { runPythonReact } from './src/python/client/reactPython.tsx';
Expand Down
11 changes: 7 additions & 4 deletions packages/examples/react_statemachine.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
</head>

<body>
<h2>React: Langium Statemachine Language Client & Language Server (Worker)</h2>
<button type="button" id="button-start">Start</button>
<label>Enable Strict mode:</label><input type="checkbox" id="checkbox-strictmode" />
<button type="button" id="button-dispose">Dispose</button>
<div class="exampleHeadelineDiv">
<b class="exampleHeadeline">React: Langium Statemachine Language Client & Language Server (Worker)</b> - [<a href="/index.html">Back to Index</a>]
<br>
<button type="button" id="button-start">Start</button>
<label>Enable Strict mode:</label><input type="checkbox" id="checkbox-strictmode" />
<button type="button" id="button-dispose">Dispose</button>
</div>
<div id="monaco-editor-root"></div>
<script type="module">
import { runStatemachineReact } from './src/langium/statemachine/main-react.tsx';
Expand Down
8 changes: 8 additions & 0 deletions packages/examples/resources/appPlayground/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { sayFoo } from './tester.js';

function sayHello(): string {
console.log(sayFoo());
return 'Hello';
};

sayHello();
Loading

0 comments on commit 2f5ee23

Please sign in to comment.