Skip to content

Commit

Permalink
Prepare: Make examples package externally available
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Aug 30, 2023
1 parent 8379dfe commit 194dad6
Show file tree
Hide file tree
Showing 36 changed files with 441 additions and 296 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "Launch JSON LS",
"type": "node",
"request": "launch",
"args": ["${workspaceRoot}/packages/examples/main/src/json/server/main.ts"],
"args": ["${workspaceRoot}/packages/examples/main/src/json/server/direct.ts"],
"runtimeArgs": ["--nolazy", "--loader", "ts-node/esm"],
"cwd": "${workspaceRoot}/packages/examples/main",
"internalConsoleOptions": "openOnSessionStart"
Expand All @@ -17,7 +17,7 @@
"name": "Launch Python LS",
"type": "node",
"request": "launch",
"args": ["${workspaceRoot}/packages/examples/main/src/python/server.ts"],
"args": ["${workspaceRoot}/packages/examples/main/src/python/server/direct.ts"],
"runtimeArgs": ["--nolazy", "--loader", "ts-node/esm"],
"cwd": "${workspaceRoot}/packages/examples/main",
"internalConsoleOptions": "openOnSessionStart"
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The following table describes which version of **monaco-languageclient** and **m

| monaco-languageclient | monaco-vscode-api | monaco-editor | comment |
| :---- | :---- | :--- | :--- |
| 6.4.5 | 1.81.5 | 0.41.0 | Released 2023-08-30 |
| 6.4.4 | 1.81.5 | 0.41.0 | Released 2023-08-24 |
| 6.4.3 | 1.81.3 | 0.41.0 | Released 2023-08-22 |
| 6.4.2 | 1.81.2 | 0.41.0 | Released 2023-08-19 |
Expand Down Expand Up @@ -144,9 +145,9 @@ There are a couple of different examples that demonstrate how the `monaco-langua
- The **json-client** contains the [client web app](./packages/examples/main/src/json/client/main.ts) which connects to the language server therefore requires the node server app to be run in parallel.

- [Python Language client and pyright language server example](./packages/examples/main/src/python):
- The **python-server** runs a Node.js [Express app](./packages/examples/main/src/python/server.ts) where web sockets are used to enable communication between the language server process and the client web application. The language server can be started as internal or external process. Use `npm run start:example:server:python` to start the language server (see [Server processes](#server-processes)).
- The **python-server** runs a Node.js [Express app](./packages/examples/main/src/python/server/main.ts) where web sockets are used to enable communication between the language server process and the client web application. The language server can be started as internal or external process. Use `npm run start:example:server:python` to start the language server (see [Server processes](#server-processes)).

- The **python-client** contains the [client web app](./packages/examples/main/src/python/client.ts) which connects to the language server therefore requires the node server app to be run in parallel.
- The **python-client** contains the [client web app](./packages/examples/main/src/python/client/main.ts) which connects to the language server therefore requires the node server app to be run in parallel.

- Langium examples:
- [Langium](https://github.com/eclipse-langium/langium) grammar language **langium-web-worker-language-server** example located in [./packages/examples/main/src/langium](./packages/examples/main/src/langium) contains both the [language client](./packages/examples/main/src/langium/langiumClient.ts) and the [langauge server (web worker)](./packages/examples/main/src/langium/langiumServerWorker.ts).
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<h1>Examples</h1>

<h2>JSON language client and language server example</h2>
Please execute <b><code>npm run start:example:server:json</code></b> beforehand:<br>
Please execute <b><code>npm run start:example:server:json</code></b> beforehand:<br>
<a href="packages/examples/main/client.html">Client for Node.js Language Server</a>
<h2>Python language client and language server example</h2>
Please execute <b><code>npm run start:example:server:python</code></b> beforehand:<br>
Please execute <b><code>npm run start:example:server:python</code></b> beforehand:<br>
<a href="packages/examples/main/python.html">Client for Python Pyright Language Server</a>
<br><br>
<h2>Langium client and language server examples</h2>
Expand Down
322 changes: 169 additions & 153 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this npm module are documented in this file.

## [6.4.5] - 2023-08-30

- Use direct `monaco-editor` imports
- Make examples publicly available

## [6.4.4] - 2023-08-24

- Update to `monaco-vscode-api` `1.81.5`
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monaco-languageclient",
"version": "6.4.4",
"version": "6.4.5",
"description": "Monaco Language client implementation",
"author": {
"name": "TypeFox GmbH",
Expand Down
7 changes: 7 additions & 0 deletions packages/examples/main/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to this npm module are documented in this file.

## [6.4.5] - 2023-08-30

- First release of the `monaco-languageclient-examples` package
11 changes: 11 additions & 0 deletions packages/examples/main/License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) 2018-2023 TypeFox GmbH (http://www.typefox.io)

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 changes: 17 additions & 0 deletions packages/examples/main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Monaco Language Client Examples

[![Gitpod - Code Now](https://img.shields.io/badge/Gitpod-code%20now-blue.svg?longCache=true)](https://gitpod.io#https://github.com/TypeFox/monaco-languageclient)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?longCache=true)](https://github.com/TypeFox/monaco-languageclient/labels/help%20wanted)
[![monaco-languageclient](https://github.com/TypeFox/monaco-languageclient/actions/workflows/actions.yml/badge.svg)](https://github.com/TypeFox/monaco-languageclient/actions/workflows/actions.yml)
[![NPM Version](https://img.shields.io/npm/v/monaco-languageclient-examples.svg)](https://www.npmjs.com/package/monaco-languageclient-examples)
[![NPM Download](https://img.shields.io/npm/dt/monaco-languageclient-examples.svg)](https://www.npmjs.com/package/monaco-languageclient-examples)

This package contains [all examples from the monaco-languageclient repository](https://github.com/TypeFox/monaco-languageclient/blob/main/README.md#examples).

## CHANGELOG

All changes are noted in the [CHANGELOG](https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/main/CHANGELOG.md).

## License

[MIT](https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/main/License.txt)
5 changes: 4 additions & 1 deletion packages/examples/main/browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<body>
<h2>Monaco Language Client Browser Sample</h2>
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
<script type="module" src="./src/browser/main.ts"></script>
<script type="module">
import { startBrowserEditor } from "./src/browser/main.ts";
startBrowserEditor();
</script>
</body>
</html>
5 changes: 4 additions & 1 deletion packages/examples/main/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<body>
<h2>Monaco Language Client Node.js Sample</h2>
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
<script type="module" src="./src/json/client/main.ts"></script>
<script type="module">
import { startJsonClient } from "./src/json/client/main.ts";
startJsonClient();
</script>
</body>

</html>
5 changes: 4 additions & 1 deletion packages/examples/main/langium_client.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<body>
<h2>Client & Langium Grammar DSL Web Worker Language Server Example</h2>
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
<script type="module" src="./src/langium/langiumClient.ts"></script>
<script type="module">
import { startLangiumClient } from "./src/langium/langiumClient.ts";
startLangiumClient();
</script>
<div id="panel"></div>
</body>

Expand Down
63 changes: 50 additions & 13 deletions packages/examples/main/package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,62 @@
{
"name": "examples-main",
"version": "1.0.0",
"private": true,
"name": "monaco-languageclient-examples",
"version": "6.4.5-next.1",
"description": "Monaco Language client examples",
"author": {
"name": "TypeFox GmbH",
"url": "http://www.typefox.io"
},
"homepage": "https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/main/README.md",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/TypeFox/monaco-languageclient",
"directory": "packages/examples/main"
},
"bugs": {
"url": "https://github.com/TypeFox/monaco-languageclient/issues"
},
"type": "module",
"main": "./dist/common.js",
"module": "./dist/common.js",
"main": "./dist/index.js",
"module": "./dist/index.js",
"exports": {
".": {
"types": "./dist/common.d.ts",
"default": "./dist/common.js"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./node": {
"types": "./dist/node.d.ts",
"default": "./dist/node.js"
},
"./langiumWorker": {
"types": "./dist/langium/langiumServerWorker.d.ts",
"default": "./dist/worker/langiumServerWorker.js"
}
},
"typesVersions": {
"*": {
".": [
"dist/common.d.ts"
"dist/index"
],
"node": [
"dist/node"
],
"langiumWorker": [
"dist/langium/langiumServerWorker"
]
}
},
"dependencies": {
"express": "~4.18.2",
"langium": "~2.0.0",
"langium": "~2.0.1",
"langium-statemachine-dsl": "~2.0.0",
"monaco-editor-workers": "~0.41.0",
"monaco-languageclient": "~6.4.4",
"monaco-languageclient": "~6.4.5",
"pyright": "~1.1.322",
"react": "~18.2.0",
"react-dom": "~18.2.0",
"request-light": "~0.7.0",
"vscode-json-languageservice": "~5.3.5",
"vscode-json-languageservice": "~5.3.6",
"vscode-languageserver": "~8.1.0",
"vscode-ws-jsonrpc": "~3.0.0",
"ws": "~8.13.0"
Expand All @@ -45,6 +73,15 @@
"node": "18.17.1",
"npm": "9.6.7"
},
"files": [
"dist",
"src",
"*.html",
"*.ts",
"README.md",
"CHANGELOG.md",
"License.txt"
],
"scripts": {
"clean": "shx rm -fr dist *.tsbuildinfo",
"compile": "tsc --build tsconfig.src.json",
Expand All @@ -53,7 +90,7 @@
"build:worker:statemachine": "esbuild ../../../node_modules/langium-statemachine-dsl/out/language-server/main-browser.js --bundle --tree-shaking=true --minify --format=iife --outfile=./dist/worker/statemachineServerWorker.js",
"build:worker:langium": "esbuild ./src/langium/langiumServerWorker.js --bundle --tree-shaking=true --minify --format=iife --outfile=./dist/worker/langiumServerWorker.js",
"build": "npm run build:msg && npm run clean && npm run compile && npm run build:worker:statemachine && npm run build:worker:langium",
"start:server:json": "node --loader ts-node/esm src/json/server/main.ts",
"start:server:python": "node --loader ts-node/esm src/python/server.ts"
"start:server:json": "node --loader ts-node/esm src/json/server/direct.ts",
"start:server:python": "node --loader ts-node/esm src/python/server/direct.ts"
}
}
5 changes: 4 additions & 1 deletion packages/examples/main/python.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<body>
<h2>Monaco Language Client Python Example</h2>
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
<script type="module" src="./src/python/client.ts"></script>
<script type="module">
import { startPythonClient } from "./src/python/client/main.ts";
startPythonClient();
</script>
</body>

</html>
5 changes: 4 additions & 1 deletion packages/examples/main/react.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<body>
<h2>Monaco Language Client React Client Example</h2>
<div id="root" />
<script type="module" src="./src/react/main.tsx"></script>
<script type="module">
import { startReactJsonClient } from "./src/react/main.tsx";
startReactJsonClient();
</script>
</body>

</html>
7 changes: 3 additions & 4 deletions packages/examples/main/src/browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { getLanguageService, TextDocument } from 'vscode-json-languageservice';
import { createConverter as createCodeConverter } from 'vscode-languageclient/lib/common/codeConverter.js';
import { createConverter as createProtocolConverter } from 'vscode-languageclient/lib/common/protocolConverter.js';
import { createDefaultJsonContent, createJsonEditor, performInit } from '../common.js';

import 'vscode/default-extensions/theme-defaults';
import 'vscode/default-extensions/json';
import { buildWorkerDefinition } from 'monaco-editor-workers';
buildWorkerDefinition('../../../node_modules/monaco-editor-workers/dist/workers/', new URL('', window.location.href).href, false);

const codeConverter = createCodeConverter();
const protocolConverter = createProtocolConverter(undefined, true, true);

const createEditor = async () => {
export const startBrowserEditor = async () => {
let mainVscodeDocument: VsCodeTextDocument | undefined;
const languageId = 'json';

Expand Down Expand Up @@ -127,5 +128,3 @@ const createEditor = async () => {
validate();
});
};

createEditor();
13 changes: 13 additions & 0 deletions packages/examples/main/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2018-2022 TypeFox GmbH (http://www.typefox.io). All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

export * from './common.js';
export * from './browser/main.js';
export * from './json/client/main.js';
export * from './langium/langiumClient.js';
export * from './langium/statemachineClient.js';
export * from './python/client/main.js';
export * from './react/app.js';
export * from './react/main.js';
4 changes: 1 addition & 3 deletions packages/examples/main/src/json/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createDefaultJsonContent, createJsonEditor, createUrl, createWebSocketA
import { buildWorkerDefinition } from 'monaco-editor-workers';
buildWorkerDefinition('../../../node_modules/monaco-editor-workers/dist/workers/', new URL('', window.location.href).href, false);

const start = async () => {
export const startJsonClient = async () => {
// use the same common method to create a monaco editor for json
await performInit(true);
await createJsonEditor({
Expand All @@ -18,5 +18,3 @@ const start = async () => {
const url = createUrl('localhost', 3000, '/sampleServer');
createWebSocketAndStartClient(url);
};

start();
7 changes: 7 additions & 0 deletions packages/examples/main/src/json/server/direct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2018-2022 TypeFox GmbH (http://www.typefox.io). All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import { runJsonServer } from './main.js';

runJsonServer();
11 changes: 2 additions & 9 deletions packages/examples/main/src/json/server/json-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import { readFile } from 'fs';
import requestLight from 'request-light';
import URI from 'vscode-uri';
import { MessageReader, MessageWriter } from 'vscode-jsonrpc';
import { _Connection, TextDocuments, DocumentSymbolParams, createConnection } from 'vscode-languageserver/lib/node/main.js';
import { } from 'vscode-ws-jsonrpc';
import { _Connection, TextDocuments, DocumentSymbolParams } from 'vscode-languageserver/lib/node/main.js';
import {
Diagnostic, Command, CompletionList, CompletionItem, Hover,
SymbolInformation, TextEdit, FoldingRange, ColorInformation, ColorPresentation
Expand All @@ -15,13 +15,6 @@ import { TextDocumentPositionParams, DocumentRangeFormattingParams, ExecuteComma
import { getLanguageService, LanguageService, JSONDocument } from 'vscode-json-languageservice';
import { TextDocument } from 'vscode-languageserver-textdocument';

export function start(reader: MessageReader, writer: MessageWriter): JsonServer {
const connection = createConnection(reader, writer);
const server = new JsonServer(connection);
server.start();
return server;
}

export class JsonServer {
protected workspaceRoot: URI.URI | undefined;

Expand Down
Loading

0 comments on commit 194dad6

Please sign in to comment.