monaco-languageclient-examples 6.4.5-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/License.txt +11 -0
- package/README.md +17 -0
- package/browser.html +16 -0
- package/client.html +16 -0
- package/dist/browser/main.d.ts +2 -0
- package/dist/browser/main.d.ts.map +1 -0
- package/dist/browser/main.js +111 -0
- package/dist/browser/main.js.map +1 -0
- package/dist/common.d.ts +22 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +109 -0
- package/dist/common.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/json/client/main.d.ts +2 -0
- package/dist/json/client/main.d.ts.map +1 -0
- package/dist/json/client/main.js +19 -0
- package/dist/json/client/main.js.map +1 -0
- package/dist/json/server/json-server.d.ts +36 -0
- package/dist/json/server/json-server.d.ts.map +1 -0
- package/dist/json/server/json-server.js +216 -0
- package/dist/json/server/json-server.js.map +1 -0
- package/dist/json/server/main.d.ts +2 -0
- package/dist/json/server/main.d.ts.map +1 -0
- package/dist/json/server/main.js +64 -0
- package/dist/json/server/main.js.map +1 -0
- package/dist/langium/langiumClient.d.ts +2 -0
- package/dist/langium/langiumClient.d.ts.map +1 -0
- package/dist/langium/langiumClient.js +130 -0
- package/dist/langium/langiumClient.js.map +1 -0
- package/dist/langium/langiumServerWorker.d.ts +2 -0
- package/dist/langium/langiumServerWorker.d.ts.map +1 -0
- package/dist/langium/langiumServerWorker.js +18 -0
- package/dist/langium/langiumServerWorker.js.map +1 -0
- package/dist/langium/statemachineClient.d.ts +2 -0
- package/dist/langium/statemachineClient.d.ts.map +1 -0
- package/dist/langium/statemachineClient.js +140 -0
- package/dist/langium/statemachineClient.js.map +1 -0
- package/dist/node.d.ts +5 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +9 -0
- package/dist/node.js.map +1 -0
- package/dist/python/client.d.ts +3 -0
- package/dist/python/client.d.ts.map +1 -0
- package/dist/python/client.js +157 -0
- package/dist/python/client.js.map +1 -0
- package/dist/python/server.d.ts +2 -0
- package/dist/python/server.d.ts.map +1 -0
- package/dist/python/server.js +105 -0
- package/dist/python/server.js.map +1 -0
- package/dist/react/app.d.ts +10 -0
- package/dist/react/app.d.ts.map +1 -0
- package/dist/react/app.js +45 -0
- package/dist/react/app.js.map +1 -0
- package/dist/react/main.d.ts +2 -0
- package/dist/react/main.d.ts.map +1 -0
- package/dist/react/main.js +14 -0
- package/dist/react/main.js.map +1 -0
- package/dist/utils/fs-utils.d.ts +5 -0
- package/dist/utils/fs-utils.d.ts.map +1 -0
- package/dist/utils/fs-utils.js +14 -0
- package/dist/utils/fs-utils.js.map +1 -0
- package/dist/worker/langiumServerWorker.js +210 -0
- package/dist/worker/statemachineServerWorker.js +534 -0
- package/langium_client.html +17 -0
- package/package.json +96 -0
- package/python.html +16 -0
- package/react.html +16 -0
- package/src/browser/main.ts +131 -0
- package/src/common.ts +130 -0
- package/src/index.ts +13 -0
- package/src/json/client/main.ts +22 -0
- package/src/json/server/json-server.ts +265 -0
- package/src/json/server/main.ts +68 -0
- package/src/langium/example.langium +215 -0
- package/src/langium/example.statemachine +26 -0
- package/src/langium/langium.configuration.json +164 -0
- package/src/langium/langium.tmLanguage.json +290 -0
- package/src/langium/langiumClient.ts +146 -0
- package/src/langium/langiumServerWorker.ts +21 -0
- package/src/langium/statemachineClient.ts +151 -0
- package/src/node.ts +9 -0
- package/src/python/client.ts +170 -0
- package/src/python/server.ts +114 -0
- package/src/react/app.tsx +73 -0
- package/src/react/main.tsx +19 -0
- package/src/utils/fs-utils.ts +14 -0
- package/statemachine_client.html +16 -0
- package/vite.statemachine-worker.ts +17 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<title>Client & Langium Grammar DSL Web Worker Language Server Example</title>
|
|
6
|
+
<meta charset="UTF-8" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body>
|
|
11
|
+
<h2>Client & Langium Grammar DSL Web Worker Language Server Example</h2>
|
|
12
|
+
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
|
|
13
|
+
<script type="module" src="./src/langium/langiumClient.ts"></script>
|
|
14
|
+
<div id="panel"></div>
|
|
15
|
+
</body>
|
|
16
|
+
|
|
17
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "monaco-languageclient-examples",
|
|
3
|
+
"version": "6.4.5-next.0",
|
|
4
|
+
"description": "Monaco Language client examples",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "TypeFox GmbH",
|
|
7
|
+
"url": "http://www.typefox.io"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/main/README.md",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/TypeFox/monaco-languageclient",
|
|
14
|
+
"directory": "packages/examples/main"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/TypeFox/monaco-languageclient/issues"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./node": {
|
|
28
|
+
"types": "./dist/node.d.ts",
|
|
29
|
+
"default": "./dist/node.js"
|
|
30
|
+
},
|
|
31
|
+
"./langiumWorker": {
|
|
32
|
+
"types": "./dist/langium/langiumServerWorker.d.ts",
|
|
33
|
+
"default": "./dist/worker/langiumServerWorker.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"typesVersions": {
|
|
37
|
+
"*": {
|
|
38
|
+
".": [
|
|
39
|
+
"dist/index"
|
|
40
|
+
],
|
|
41
|
+
"node": [
|
|
42
|
+
"dist/node"
|
|
43
|
+
],
|
|
44
|
+
"langiumWorker": [
|
|
45
|
+
"dist/langium/langiumServerWorker"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"express": "~4.18.2",
|
|
51
|
+
"langium": "~2.0.1",
|
|
52
|
+
"langium-statemachine-dsl": "~2.0.0",
|
|
53
|
+
"monaco-editor-workers": "~0.41.0",
|
|
54
|
+
"monaco-languageclient": "~6.4.5",
|
|
55
|
+
"pyright": "~1.1.322",
|
|
56
|
+
"react": "~18.2.0",
|
|
57
|
+
"react-dom": "~18.2.0",
|
|
58
|
+
"request-light": "~0.7.0",
|
|
59
|
+
"vscode-json-languageservice": "~5.3.6",
|
|
60
|
+
"vscode-languageserver": "~8.1.0",
|
|
61
|
+
"vscode-ws-jsonrpc": "~3.0.0",
|
|
62
|
+
"ws": "~8.13.0"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@types/ws": "~8.5.5",
|
|
66
|
+
"@types/express": "~4.17.17",
|
|
67
|
+
"@types/react": "~18.2.20",
|
|
68
|
+
"@types/react-dom": "~18.2.7",
|
|
69
|
+
"ts-node": "~10.9.1",
|
|
70
|
+
"vscode-languageserver-types": "~3.17.3"
|
|
71
|
+
},
|
|
72
|
+
"volta": {
|
|
73
|
+
"node": "18.17.1",
|
|
74
|
+
"npm": "9.6.7"
|
|
75
|
+
},
|
|
76
|
+
"files": [
|
|
77
|
+
"dist",
|
|
78
|
+
"src",
|
|
79
|
+
"*.html",
|
|
80
|
+
"*.ts",
|
|
81
|
+
"README.md",
|
|
82
|
+
"CHANGELOG.md",
|
|
83
|
+
"License.txt"
|
|
84
|
+
],
|
|
85
|
+
"scripts": {
|
|
86
|
+
"clean": "shx rm -fr dist *.tsbuildinfo",
|
|
87
|
+
"compile": "tsc --build tsconfig.src.json",
|
|
88
|
+
"build:msg": "echo Building main examples:",
|
|
89
|
+
"build:worker:vite": "vite --config vite.statemachine-worker.ts build",
|
|
90
|
+
"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",
|
|
91
|
+
"build:worker:langium": "esbuild ./src/langium/langiumServerWorker.js --bundle --tree-shaking=true --minify --format=iife --outfile=./dist/worker/langiumServerWorker.js",
|
|
92
|
+
"build": "npm run build:msg && npm run clean && npm run compile && npm run build:worker:statemachine && npm run build:worker:langium",
|
|
93
|
+
"start:server:json": "node --loader ts-node/esm src/json/server/main.ts",
|
|
94
|
+
"start:server:python": "node --loader ts-node/esm src/python/server.ts"
|
|
95
|
+
}
|
|
96
|
+
}
|
package/python.html
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<title>Monaco Language Client Python Example</title>
|
|
6
|
+
<meta charset="utf-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body>
|
|
11
|
+
<h2>Monaco Language Client Python Example</h2>
|
|
12
|
+
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
|
|
13
|
+
<script type="module" src="./src/python/client.ts"></script>
|
|
14
|
+
</body>
|
|
15
|
+
|
|
16
|
+
</html>
|
package/react.html
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<title>Monaco Language Client React Client Example</title>
|
|
6
|
+
<meta charset="utf-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body>
|
|
11
|
+
<h2>Monaco Language Client React Client Example</h2>
|
|
12
|
+
<div id="root" />
|
|
13
|
+
<script type="module" src="./src/react/main.tsx"></script>
|
|
14
|
+
</body>
|
|
15
|
+
|
|
16
|
+
</html>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) 2018-2022 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
|
+
import { languages, workspace, TextDocument as VsCodeTextDocument } from 'vscode';
|
|
6
|
+
import { getLanguageService, TextDocument } from 'vscode-json-languageservice';
|
|
7
|
+
import { createConverter as createCodeConverter } from 'vscode-languageclient/lib/common/codeConverter.js';
|
|
8
|
+
import { createConverter as createProtocolConverter } from 'vscode-languageclient/lib/common/protocolConverter.js';
|
|
9
|
+
import { createDefaultJsonContent, createJsonEditor, performInit } from '../common.js';
|
|
10
|
+
|
|
11
|
+
import { buildWorkerDefinition } from 'monaco-editor-workers';
|
|
12
|
+
buildWorkerDefinition('../../../node_modules/monaco-editor-workers/dist/workers/', new URL('', window.location.href).href, false);
|
|
13
|
+
|
|
14
|
+
const codeConverter = createCodeConverter();
|
|
15
|
+
const protocolConverter = createProtocolConverter(undefined, true, true);
|
|
16
|
+
|
|
17
|
+
const createEditor = async () => {
|
|
18
|
+
let mainVscodeDocument: VsCodeTextDocument | undefined;
|
|
19
|
+
const languageId = 'json';
|
|
20
|
+
|
|
21
|
+
await performInit(true);
|
|
22
|
+
|
|
23
|
+
workspace.onDidOpenTextDocument((_event) => {
|
|
24
|
+
mainVscodeDocument = workspace.textDocuments[0];
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const jsonEditor = await createJsonEditor({
|
|
28
|
+
htmlElement: document.getElementById('container')!,
|
|
29
|
+
content: createDefaultJsonContent()
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const createDocument = (vscodeDocument: VsCodeTextDocument) => {
|
|
33
|
+
return TextDocument.create(vscodeDocument.uri.toString(), vscodeDocument.languageId, vscodeDocument.version, vscodeDocument.getText());
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const resolveSchema = (url: string): Promise<string> => {
|
|
37
|
+
const promise = new Promise<string>((resolve, reject) => {
|
|
38
|
+
const xhr = new XMLHttpRequest();
|
|
39
|
+
xhr.onload = () => resolve(xhr.responseText);
|
|
40
|
+
xhr.onerror = () => reject(xhr.statusText);
|
|
41
|
+
xhr.open('GET', url, true);
|
|
42
|
+
xhr.send();
|
|
43
|
+
});
|
|
44
|
+
return promise;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const jsonService = getLanguageService({
|
|
48
|
+
schemaRequestService: resolveSchema
|
|
49
|
+
});
|
|
50
|
+
const pendingValidationRequests = new Map<string, number>();
|
|
51
|
+
|
|
52
|
+
languages.registerCompletionItemProvider(languageId, {
|
|
53
|
+
async provideCompletionItems(vscodeDocument, position, _token, _context) {
|
|
54
|
+
const document = createDocument(vscodeDocument);
|
|
55
|
+
const jsonDocument = jsonService.parseJSONDocument(document);
|
|
56
|
+
const completionList = await jsonService.doComplete(document, codeConverter.asPosition(position), jsonDocument);
|
|
57
|
+
return protocolConverter.asCompletionResult(completionList);
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
resolveCompletionItem(item, _token) {
|
|
61
|
+
return jsonService.doResolve(codeConverter.asCompletionItem(item)).then(result => protocolConverter.asCompletionItem(result));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
languages.registerDocumentRangeFormattingEditProvider(languageId, {
|
|
66
|
+
provideDocumentRangeFormattingEdits(vscodeDocument, range, options, _token) {
|
|
67
|
+
const document = createDocument(vscodeDocument);
|
|
68
|
+
const edits = jsonService.format(document, codeConverter.asRange(range), codeConverter.asFormattingOptions(options, {}));
|
|
69
|
+
return protocolConverter.asTextEdits(edits);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
languages.registerDocumentSymbolProvider(languageId, {
|
|
74
|
+
provideDocumentSymbols(vscodeDocument, _token) {
|
|
75
|
+
const document = createDocument(vscodeDocument);
|
|
76
|
+
const jsonDocument = jsonService.parseJSONDocument(document);
|
|
77
|
+
return protocolConverter.asSymbolInformations(jsonService.findDocumentSymbols(document, jsonDocument));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
languages.registerHoverProvider(languageId, {
|
|
82
|
+
provideHover(vscodeDocument, position, _token) {
|
|
83
|
+
const document = createDocument(vscodeDocument);
|
|
84
|
+
const jsonDocument = jsonService.parseJSONDocument(document);
|
|
85
|
+
return jsonService.doHover(document, codeConverter.asPosition(position), jsonDocument).then((hover) => {
|
|
86
|
+
return protocolConverter.asHover(hover)!;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const validate = () => {
|
|
92
|
+
const document = createDocument(mainVscodeDocument!);
|
|
93
|
+
cleanPendingValidation(document);
|
|
94
|
+
pendingValidationRequests.set(document.uri, window.setTimeout(() => {
|
|
95
|
+
pendingValidationRequests.delete(document.uri);
|
|
96
|
+
doValidate(document);
|
|
97
|
+
}));
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const cleanPendingValidation = (document: TextDocument) => {
|
|
101
|
+
const request = pendingValidationRequests.get(document.uri);
|
|
102
|
+
if (request !== undefined) {
|
|
103
|
+
window.clearTimeout(request);
|
|
104
|
+
pendingValidationRequests.delete(document.uri);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const diagnosticCollection = languages.createDiagnosticCollection('json');
|
|
109
|
+
const doValidate = (document: TextDocument) => {
|
|
110
|
+
if (document.getText().length === 0) {
|
|
111
|
+
cleanDiagnostics();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const jsonDocument = jsonService.parseJSONDocument(document);
|
|
115
|
+
|
|
116
|
+
jsonService.doValidation(document, jsonDocument).then(async (pDiagnostics) => {
|
|
117
|
+
const diagnostics = await protocolConverter.asDiagnostics(pDiagnostics);
|
|
118
|
+
diagnosticCollection.set(jsonEditor.uri, diagnostics);
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const cleanDiagnostics = () => {
|
|
123
|
+
diagnosticCollection.clear();
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
jsonEditor.modelRef.object.textEditorModel!.onDidChangeContent(() => {
|
|
127
|
+
validate();
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
createEditor();
|
package/src/common.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) 2018-2022 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 { editor, languages, Uri } from 'monaco-editor';
|
|
7
|
+
import { createConfiguredEditor, createModelReference, IReference, ITextFileEditorModel } from 'vscode/monaco';
|
|
8
|
+
import 'vscode/default-extensions/theme-defaults';
|
|
9
|
+
import 'vscode/default-extensions/json';
|
|
10
|
+
import { initServices, MonacoLanguageClient } from 'monaco-languageclient';
|
|
11
|
+
import { CloseAction, ErrorAction, MessageTransports } from 'vscode-languageclient';
|
|
12
|
+
import { WebSocketMessageReader, WebSocketMessageWriter, toSocket } from 'vscode-ws-jsonrpc';
|
|
13
|
+
|
|
14
|
+
export const createLanguageClient = (transports: MessageTransports): MonacoLanguageClient => {
|
|
15
|
+
return new MonacoLanguageClient({
|
|
16
|
+
name: 'Sample Language Client',
|
|
17
|
+
clientOptions: {
|
|
18
|
+
// use a language id as a document selector
|
|
19
|
+
documentSelector: ['json'],
|
|
20
|
+
// disable the default error handler
|
|
21
|
+
errorHandler: {
|
|
22
|
+
error: () => ({ action: ErrorAction.Continue }),
|
|
23
|
+
closed: () => ({ action: CloseAction.DoNotRestart })
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
// create a language client connection from the JSON RPC connection on demand
|
|
27
|
+
connectionProvider: {
|
|
28
|
+
get: () => {
|
|
29
|
+
return Promise.resolve(transports);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export const createUrl = (hostname: string, port: number, path: string, searchParams: Record<string, any> = {}, secure: boolean = location.protocol === 'https:'): string => {
|
|
35
|
+
const protocol = secure ? 'wss' : 'ws';
|
|
36
|
+
const url = new URL(`${protocol}://${hostname}:${port}${path}`);
|
|
37
|
+
|
|
38
|
+
for (let [key, value] of Object.entries(searchParams)) {
|
|
39
|
+
if (value instanceof Array) {
|
|
40
|
+
value = value.join(',');
|
|
41
|
+
}
|
|
42
|
+
if (value) {
|
|
43
|
+
url.searchParams.set(key, value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return url.toString();
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const createWebSocketAndStartClient = (url: string): WebSocket => {
|
|
51
|
+
const webSocket = new WebSocket(url);
|
|
52
|
+
webSocket.onopen = () => {
|
|
53
|
+
const socket = toSocket(webSocket);
|
|
54
|
+
const reader = new WebSocketMessageReader(socket);
|
|
55
|
+
const writer = new WebSocketMessageWriter(socket);
|
|
56
|
+
const languageClient = createLanguageClient({
|
|
57
|
+
reader,
|
|
58
|
+
writer
|
|
59
|
+
});
|
|
60
|
+
languageClient.start();
|
|
61
|
+
reader.onClose(() => languageClient.stop());
|
|
62
|
+
};
|
|
63
|
+
return webSocket;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const createDefaultJsonContent = (): string => {
|
|
67
|
+
return `{
|
|
68
|
+
"$schema": "http://json.schemastore.org/coffeelint",
|
|
69
|
+
"line_endings": "unix"
|
|
70
|
+
} `;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type ExampleJsonEditor = {
|
|
74
|
+
languageId: string;
|
|
75
|
+
editor: editor.IStandaloneCodeEditor;
|
|
76
|
+
uri: Uri;
|
|
77
|
+
modelRef: IReference<ITextFileEditorModel>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const performInit = async (vscodeApiInit: boolean) => {
|
|
81
|
+
if (vscodeApiInit === true) {
|
|
82
|
+
await initServices({
|
|
83
|
+
enableThemeService: true,
|
|
84
|
+
enableTextmateService: true,
|
|
85
|
+
enableModelService: true,
|
|
86
|
+
configureEditorOrViewsService: {
|
|
87
|
+
},
|
|
88
|
+
enableKeybindingsService: true,
|
|
89
|
+
enableLanguagesService: true,
|
|
90
|
+
enableOutputService: true,
|
|
91
|
+
enableAccessibilityService: true,
|
|
92
|
+
debugLogging: false
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// register the JSON language with Monaco
|
|
96
|
+
languages.register({
|
|
97
|
+
id: 'json',
|
|
98
|
+
extensions: ['.json', '.jsonc'],
|
|
99
|
+
aliases: ['JSON', 'json'],
|
|
100
|
+
mimetypes: ['application/json']
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const createJsonEditor = async (config: {
|
|
106
|
+
htmlElement: HTMLElement,
|
|
107
|
+
content: string
|
|
108
|
+
}) => {
|
|
109
|
+
// create the model
|
|
110
|
+
const uri = Uri.parse('/tmp/model.json');
|
|
111
|
+
const modelRef = await createModelReference(uri, config.content);
|
|
112
|
+
modelRef.object.setLanguageId('json');
|
|
113
|
+
|
|
114
|
+
// create monaco editor
|
|
115
|
+
const editor = createConfiguredEditor(config.htmlElement, {
|
|
116
|
+
model: modelRef.object.textEditorModel,
|
|
117
|
+
glyphMargin: true,
|
|
118
|
+
lightbulb: {
|
|
119
|
+
enabled: true
|
|
120
|
+
},
|
|
121
|
+
automaticLayout: true
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const result = {
|
|
125
|
+
editor,
|
|
126
|
+
uri,
|
|
127
|
+
modelRef
|
|
128
|
+
} as ExampleJsonEditor;
|
|
129
|
+
return Promise.resolve(result);
|
|
130
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) 2018-2022 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
|
+
export * from './common.js';
|
|
7
|
+
export * from './browser/main.js';
|
|
8
|
+
export * from './json/client/main.js';
|
|
9
|
+
export * from './langium/langiumClient.js';
|
|
10
|
+
export * from './langium/statemachineClient.js';
|
|
11
|
+
export * from './python/client.js';
|
|
12
|
+
export * from './react/app.js';
|
|
13
|
+
export * from './react/main.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) 2018-2022 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 { createDefaultJsonContent, createJsonEditor, createUrl, createWebSocketAndStartClient, performInit } from '../../common.js';
|
|
7
|
+
import { buildWorkerDefinition } from 'monaco-editor-workers';
|
|
8
|
+
buildWorkerDefinition('../../../node_modules/monaco-editor-workers/dist/workers/', new URL('', window.location.href).href, false);
|
|
9
|
+
|
|
10
|
+
const start = async () => {
|
|
11
|
+
// use the same common method to create a monaco editor for json
|
|
12
|
+
await performInit(true);
|
|
13
|
+
await createJsonEditor({
|
|
14
|
+
htmlElement: document.getElementById('container')!,
|
|
15
|
+
content: createDefaultJsonContent()
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const url = createUrl('localhost', 3000, '/sampleServer');
|
|
19
|
+
createWebSocketAndStartClient(url);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
start();
|