monaco-languageclient-examples 2025.8.4 → 2025.8.5

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/browser/main.d.ts +1 -0
  3. package/dist/browser/main.d.ts.map +1 -1
  4. package/dist/browser/main.js +2 -1
  5. package/dist/browser/main.js.map +1 -1
  6. package/dist/langium/langium-dsl/config/extendedConfig.d.ts +1 -6
  7. package/dist/langium/langium-dsl/config/extendedConfig.d.ts.map +1 -1
  8. package/dist/langium/langium-dsl/config/extendedConfig.js +77 -23
  9. package/dist/langium/langium-dsl/config/extendedConfig.js.map +1 -1
  10. package/dist/langium/langium-dsl/config/langium.configuration.json +10 -40
  11. package/dist/langium/langium-dsl/config/langium.tmLanguage.json +1 -1
  12. package/dist/langium/langium-dsl/main.d.ts +2 -0
  13. package/dist/langium/langium-dsl/main.d.ts.map +1 -0
  14. package/dist/langium/langium-dsl/main.js +26 -0
  15. package/dist/langium/langium-dsl/main.js.map +1 -0
  16. package/dist/langium/statemachine/main-react.d.ts.map +1 -1
  17. package/dist/langium/statemachine/main-react.js +6 -1
  18. package/dist/langium/statemachine/main-react.js.map +1 -1
  19. package/dist/python/client/reactPython.d.ts.map +1 -1
  20. package/dist/python/client/reactPython.js +6 -1
  21. package/dist/python/client/reactPython.js.map +1 -1
  22. package/ghp_langium_extended.html +3 -3
  23. package/index.html +1 -1
  24. package/langium_extended.html +4 -6
  25. package/package.json +6 -6
  26. package/src/browser/main.ts +2 -1
  27. package/src/langium/langium-dsl/config/extendedConfig.ts +87 -31
  28. package/src/langium/langium-dsl/config/langium.configuration.json +128 -158
  29. package/src/langium/langium-dsl/config/langium.tmLanguage.json +271 -271
  30. package/src/langium/langium-dsl/main.ts +31 -0
  31. package/src/langium/statemachine/main-react.tsx +6 -0
  32. package/src/python/client/reactPython.tsx +6 -0
  33. package/vite.production.base.ts +0 -1
  34. package/dist/langium/langium-dsl/config/classicConfig.d.ts +0 -7
  35. package/dist/langium/langium-dsl/config/classicConfig.d.ts.map +0 -1
  36. package/dist/langium/langium-dsl/config/classicConfig.js +0 -74
  37. package/dist/langium/langium-dsl/config/classicConfig.js.map +0 -1
  38. package/dist/langium/langium-dsl/wrapperLangium.d.ts +0 -2
  39. package/dist/langium/langium-dsl/wrapperLangium.d.ts.map +0 -1
  40. package/dist/langium/langium-dsl/wrapperLangium.js +0 -86
  41. package/dist/langium/langium-dsl/wrapperLangium.js.map +0 -1
  42. package/ghp_langium_classic.html +0 -26
  43. package/langium_classic.html +0 -26
  44. package/src/langium/langium-dsl/config/classicConfig.ts +0 -88
  45. package/src/langium/langium-dsl/wrapperLangium.ts +0 -95
@@ -3,39 +3,105 @@
3
3
  * Licensed under the MIT License. See LICENSE in the package root for license information.
4
4
  * ------------------------------------------------------------------------------------------ */
5
5
 
6
- import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
6
+ import * as vscode from 'vscode';
7
7
  import { LogLevel } from '@codingame/monaco-vscode-api';
8
- import '../../../../resources/vsix/github-vscode-theme.vsix';
9
- import { MessageTransports } from 'vscode-languageclient';
10
- import type { MonacoVscodeApiConfig } from 'monaco-languageclient/vscodeApiWrapper';
8
+ import { InMemoryFileSystemProvider, registerFileSystemOverlay, type IFileWriteOptions } from '@codingame/monaco-vscode-files-service-override';
9
+ import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
10
+ import type { EditorAppConfig } from 'monaco-languageclient/editorApp';
11
11
  import type { LanguageClientConfig } from 'monaco-languageclient/lcwrapper';
12
+ import { type MonacoVscodeApiConfig, type OverallConfigType } from 'monaco-languageclient/vscodeApiWrapper';
12
13
  import { configureDefaultWorkerFactory } from 'monaco-languageclient/workerFactory';
14
+ import { BrowserMessageReader, BrowserMessageWriter } from 'vscode-languageclient/browser.js';
15
+ import langiumGrammarLangium from '../../../../resources/langium/langium-dsl/langium-grammar.langium?raw';
16
+ import langiumTypesLangium from '../../../../resources/langium/langium-dsl/langium-types.langium?raw';
17
+ import type { ExampleAppConfig } from '../../../common/client/utils.js';
18
+ import workerUrl from '../worker/langium-server?worker&url';
13
19
  import langiumLanguageConfig from './langium.configuration.json?raw';
14
20
  import langiumTextmateGrammar from './langium.tmLanguage.json?raw';
15
- import text from '../../../../resources/langium/langium-dsl//example.langium?raw';
16
- import type { ExampleAppConfig } from '../../../common/client/utils.js';
17
- import type { EditorAppConfig } from 'monaco-languageclient/editorApp';
18
-
19
- export const setupLangiumClientExtended = (params: {
20
- worker: Worker
21
- messageTransports?: MessageTransports,
22
- }): ExampleAppConfig => {
23
21
 
22
+ export const setupLangiumClientExtended = async (): Promise<ExampleAppConfig> => {
23
+ const overallConfigType: OverallConfigType = 'extended';
24
24
  const extensionFilesOrContents = new Map<string, string | URL>();
25
25
  // vite build is easier with string content
26
- extensionFilesOrContents.set('/langium-configuration.json', langiumLanguageConfig);
27
- extensionFilesOrContents.set('/langium-grammar.json', langiumTextmateGrammar);
26
+ extensionFilesOrContents.set('/workspace/langium-configuration.json', langiumLanguageConfig);
27
+ extensionFilesOrContents.set('/workspace/langium-grammar.json', langiumTextmateGrammar);
28
28
 
29
+ const loadLangiumWorker = () => {
30
+ console.log(`Langium worker URL: ${workerUrl}`);
31
+ return new Worker(workerUrl, {
32
+ type: 'module',
33
+ name: 'Langium LS',
34
+ });
35
+ };
36
+
37
+ const worker = loadLangiumWorker();
38
+ const reader = new BrowserMessageReader(worker);
39
+ const writer = new BrowserMessageWriter(worker);
40
+ reader.listen((message) => {
41
+ console.log('Received message from worker:', message);
42
+ });
43
+
44
+ // prepare all resources that should be preloaded
45
+ const workspaceUri = vscode.Uri.file('/workspace');
46
+ const langiumGrammarLangiumUri = vscode.Uri.file('/workspace/langium-grammar.langium');
47
+ const langiumTypesLangiumUri = vscode.Uri.file('/workspace/langium-types.langium');
48
+ const fileSystemProvider = new InMemoryFileSystemProvider();
49
+ const textEncoder = new TextEncoder();
50
+
51
+ const options: IFileWriteOptions = {
52
+ atomic: false,
53
+ unlock: false,
54
+ create: true,
55
+ overwrite: true
56
+ };
57
+ await fileSystemProvider.mkdir(workspaceUri);
58
+ await fileSystemProvider.writeFile(langiumGrammarLangiumUri, textEncoder.encode(langiumGrammarLangium), options);
59
+ await fileSystemProvider.writeFile(langiumTypesLangiumUri, textEncoder.encode(langiumTypesLangium), options);
60
+ registerFileSystemOverlay(1, fileSystemProvider);
61
+
62
+ const editorAppConfig: EditorAppConfig = {
63
+ $type: overallConfigType
64
+ };
65
+
66
+ const innerHtml = `<div id="editorsDiv">
67
+ <div id="editors"></div>
68
+ </div>`;
69
+ const viewsInit = async () => {
70
+ const { Parts, onPartVisibilityChange, isPartVisibile, attachPart, } = await import('@codingame/monaco-vscode-views-service-override');
71
+
72
+ for (const config of [
73
+ { part: Parts.EDITOR_PART, element: '#editors' },
74
+ ]) {
75
+ attachPart(config.part, document.querySelector<HTMLDivElement>(config.element)!);
76
+
77
+ if (!isPartVisibile(config.part)) {
78
+ document.querySelector<HTMLDivElement>(config.element)!.style.display = 'none';
79
+ }
80
+
81
+ onPartVisibilityChange(config.part, visible => {
82
+ document.querySelector<HTMLDivElement>(config.element)!.style.display = visible ? 'block' : 'none';
83
+ });
84
+ }
85
+ };
29
86
  const vscodeApiConfig: MonacoVscodeApiConfig = {
30
- $type: 'extended',
87
+ $type: overallConfigType,
31
88
  logLevel: LogLevel.Debug,
32
- htmlContainer: document.getElementById('monaco-editor-root')!,
89
+ htmlContainer: document.body,
33
90
  serviceOverrides: {
34
91
  ...getKeybindingsServiceOverride()
35
92
  },
93
+ viewsConfig: {
94
+ viewServiceType: 'ViewsService',
95
+ htmlAugmentationInstructions: (htmlElement: HTMLElement | null | undefined) => {
96
+ const htmlContainer = document.createElement('div', { is: 'app' });
97
+ htmlContainer.innerHTML = innerHtml;
98
+ htmlElement?.append(htmlContainer);
99
+ },
100
+ viewsInitFunc: viewsInit
101
+ },
36
102
  userConfiguration: {
37
103
  json: JSON.stringify({
38
- 'workbench.colorTheme': 'GitHub Dark High Contrast',
104
+ 'workbench.colorTheme': 'Default Dark Modern',
39
105
  'editor.guides.bracketPairsHorizontal': 'active',
40
106
  'editor.wordBasedSuggestions': 'off',
41
107
  'editor.experimental.asyncTokenization': true,
@@ -56,12 +122,12 @@ export const setupLangiumClientExtended = (params: {
56
122
  id: 'langium',
57
123
  extensions: ['.langium'],
58
124
  aliases: ['langium', 'LANGIUM'],
59
- configuration: './langium-configuration.json'
125
+ configuration: '/workspace/langium-configuration.json'
60
126
  }],
61
127
  grammars: [{
62
128
  language: 'langium',
63
129
  scopeName: 'source.langium',
64
- path: './langium-grammar.json'
130
+ path: '/workspace/langium-grammar.json'
65
131
  }]
66
132
  }
67
133
  },
@@ -76,19 +142,9 @@ export const setupLangiumClientExtended = (params: {
76
142
  connection: {
77
143
  options: {
78
144
  $type: 'WorkerDirect',
79
- worker: params.worker
145
+ worker
80
146
  },
81
- messageTransports: params.messageTransports
82
- }
83
- };
84
-
85
- const editorAppConfig: EditorAppConfig = {
86
- $type: vscodeApiConfig.$type,
87
- codeResources: {
88
- modified: {
89
- text,
90
- uri: '/workspace/grammar.langium'
91
- }
147
+ messageTransports: { reader, writer }
92
148
  }
93
149
  };
94
150
 
@@ -1,164 +1,134 @@
1
1
  {
2
- "comments": {
3
- "lineComment": "//",
4
- "blockComment": [
5
- "/*",
6
- "*/"
7
- ]
8
- },
9
- "brackets": [
10
- [
11
- "{",
12
- "}"
13
- ],
14
- [
15
- "[",
16
- "]"
17
- ],
18
- [
19
- "(",
20
- ")"
21
- ]
22
- ],
23
- "autoClosingPairs": [
24
- {
25
- "open": "{",
26
- "close": "}"
27
- },
28
- {
29
- "open": "[",
30
- "close": "]"
2
+ "comments": {
3
+ "lineComment": "//",
4
+ "blockComment": ["/*", "*/"]
31
5
  },
32
- {
33
- "open": "(",
34
- "close": ")"
35
- },
36
- {
37
- "open": "'",
38
- "close": "'",
39
- "notIn": [
40
- "string",
41
- "comment"
42
- ]
43
- },
44
- {
45
- "open": "\"",
46
- "close": "\"",
47
- "notIn": [
48
- "string"
49
- ]
50
- },
51
- {
52
- "open": "/**",
53
- "close": " */",
54
- "notIn": [
55
- "string"
56
- ]
57
- }
58
- ],
59
- "autoCloseBefore": "}])`\n\t",
60
- "surroundingPairs": [
61
- [
62
- "{",
63
- "}"
6
+ "brackets": [
7
+ ["{", "}"],
8
+ ["[", "]"],
9
+ ["(", ")"]
64
10
  ],
65
- [
66
- "[",
67
- "]"
68
- ],
69
- [
70
- "(",
71
- ")"
72
- ]
73
- ],
74
- "colorizedBracketPairs": [
75
- [
76
- "(",
77
- ")"
11
+ "autoClosingPairs": [
12
+ { "open": "{", "close": "}" },
13
+ { "open": "[", "close": "]" },
14
+ { "open": "(", "close": ")" },
15
+ {
16
+ "open": "'",
17
+ "close": "'",
18
+ "notIn": [
19
+ "string",
20
+ "comment"
21
+ ]
22
+ },
23
+ {
24
+ "open": "\"",
25
+ "close": "\"",
26
+ "notIn": [
27
+ "string"
28
+ ]
29
+ },
30
+ {
31
+ "open": "/**",
32
+ "close": " */",
33
+ "notIn": [
34
+ "string"
35
+ ]
36
+ }
78
37
  ],
79
- [
80
- "[",
81
- "]"
38
+ "autoCloseBefore": "}])`\n\t",
39
+ "surroundingPairs": [
40
+ ["{", "}"],
41
+ ["[", "]"],
42
+ ["(", ")"]
82
43
  ],
83
- [
84
- "{",
85
- "}"
86
- ],
87
- [
88
- "<",
89
- ">"
90
- ],
91
- [
92
- "'",
93
- "'"
94
- ],
95
- [
96
- "\"",
97
- "\""
98
- ],
99
- [
100
- "<",
101
- ">"
44
+ "colorizedBracketPairs": [
45
+ [
46
+ "(",
47
+ ")"
48
+ ],
49
+ [
50
+ "[",
51
+ "]"
52
+ ],
53
+ [
54
+ "{",
55
+ "}"
56
+ ],
57
+ [
58
+ "<",
59
+ ">"
60
+ ],
61
+ [
62
+ "'",
63
+ "'"
64
+ ],
65
+ [
66
+ "\"",
67
+ "\""
68
+ ],
69
+ [
70
+ "<",
71
+ ">"
72
+ ]
73
+ ],
74
+ "onEnterRules": [
75
+ {
76
+ "": "// e.g. /** | */",
77
+ "beforeText": {
78
+ "pattern": "^\\s*/\\*\\*(?!/)([^\\*]|\\*(?!/))*$"
79
+ },
80
+ "afterText": {
81
+ "pattern": "^\\s*\\*/$"
82
+ },
83
+ "action": {
84
+ "indent": "indentOutdent",
85
+ "appendText": " * "
86
+ }
87
+ },
88
+ {
89
+ "": "// e.g. /** ...|",
90
+ "beforeText": {
91
+ "pattern": "^\\s*/\\*\\*(?!/)([^\\*]|\\*(?!/))*$"
92
+ },
93
+ "action": {
94
+ "indent": "none",
95
+ "appendText": " * "
96
+ }
97
+ },
98
+ {
99
+ "": "// e.g. * ...|",
100
+ "beforeText": {
101
+ "pattern": "^(\\t|[ ])*[ ]\\*([ ]([^\\*]|\\*(?!/))*)?$"
102
+ },
103
+ "previousLineText": {
104
+ "pattern": "(?=^(\\s*(/\\*\\*|\\*)).*)(?=(?!(\\s*\\*/)))"
105
+ },
106
+ "action": {
107
+ "indent": "none",
108
+ "appendText": "* "
109
+ }
110
+ },
111
+ {
112
+ "": "// e.g. */|",
113
+ "beforeText": {
114
+ "pattern": "^(\\t|[ ])*[ ]\\*/\\s*$"
115
+ },
116
+ "action": {
117
+ "indent": "none",
118
+ "removeText": 1
119
+ }
120
+ },
121
+ {
122
+ "beforeText": ":\\s*$",
123
+ "action": {
124
+ "indent": "indent"
125
+ }
126
+ },
127
+ {
128
+ "beforeText": ";\\s*$",
129
+ "action": {
130
+ "indent": "outdent"
131
+ }
132
+ }
102
133
  ]
103
- ],
104
- "onEnterRules": [
105
- {
106
- "": "// e.g. /** | */",
107
- "beforeText": {
108
- "pattern": "^\\s*/\\*\\*(?!/)([^\\*]|\\*(?!/))*$"
109
- },
110
- "afterText": {
111
- "pattern": "^\\s*\\*/$"
112
- },
113
- "action": {
114
- "indent": "indentOutdent",
115
- "appendText": " * "
116
- }
117
- },
118
- {
119
- "": "// e.g. /** ...|",
120
- "beforeText": {
121
- "pattern": "^\\s*/\\*\\*(?!/)([^\\*]|\\*(?!/))*$"
122
- },
123
- "action": {
124
- "indent": "none",
125
- "appendText": " * "
126
- }
127
- },
128
- {
129
- "": "// e.g. * ...|",
130
- "beforeText": {
131
- "pattern": "^(\\t|[ ])*[ ]\\*([ ]([^\\*]|\\*(?!/))*)?$"
132
- },
133
- "previousLineText": {
134
- "pattern": "(?=^(\\s*(/\\*\\*|\\*)).*)(?=(?!(\\s*\\*/)))"
135
- },
136
- "action": {
137
- "indent": "none",
138
- "appendText": "* "
139
- }
140
- },
141
- {
142
- "": "// e.g. */|",
143
- "beforeText": {
144
- "pattern": "^(\\t|[ ])*[ ]\\*/\\s*$"
145
- },
146
- "action": {
147
- "indent": "none",
148
- "removeText": 1
149
- }
150
- },
151
- {
152
- "beforeText": ":\\s*$",
153
- "action": {
154
- "indent": "indent"
155
- }
156
- },
157
- {
158
- "beforeText": ";\\s*$",
159
- "action": {
160
- "indent": "outdent"
161
- }
162
- }
163
- ]
164
- }
134
+ }