Skip to content

Commit b2db3d8

Browse files
Upgrade to latest Monaco Editor version
- Treat editor worker as asset in extension for easier usage (webpack) - Use monacoConfigPlugin for vite configuration
1 parent 24384fb commit b2db3d8

File tree

10 files changed

+9232
-8034
lines changed

10 files changed

+9232
-8034
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ dist/
4141
AxonIvyEngine/
4242
container-workspace/
4343
target/
44+
45+
**/.pnpm-store*

extension/assets/monaco-workers/editor.js

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

extension/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
"@axonivy/form-editor-protocol": "~13.2.0-next.991.043a322",
3434
"@axonivy/log-view-core": "~13.2.0-next.262.10ba45f",
3535
"@axonivy/log-view-protocol": "~13.2.0-next.262.10ba45f",
36-
"@axonivy/process-editor-protocol": "~13.2.0-next.1853.34378948",
37-
"@axonivy/process-editor-inscription-protocol": "~13.2.0-next.1853.34378948",
36+
"@axonivy/process-editor-protocol": "~13.2.0-next.1899.1a3079bf",
37+
"@axonivy/process-editor-inscription-protocol": "~13.2.0-next.1899.1a3079bf",
3838
"@axonivy/variable-editor-protocol": "~13.2.0-next.863.0c776bc",
3939
"@axonivy/jsonrpc": "~13.2.0-next.936.ef2cd88",
4040
"@eclipse-glsp/vscode-integration": "2.5.0",
41+
"@codingame/monaco-vscode-editor-api": "^23.1.1",
42+
"@codingame/monaco-vscode-textmate-service-override": "^23.1.1",
4143
"@eclipse-glsp/protocol": "2.5.0",
4244
"axios": "1.13.2",
4345
"dom-serializer": "2.0.0",

extension/src/editors/build-manifest.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export interface ViteManifestEntry {
2222
}
2323

2424
export const ROOT_ENTRY = 'index.html';
25-
export const EDITOR_WORKER_ENTRY = 'editor.worker.js?worker';
2625

2726
export function parseBuildManifest(root: vscode.Uri): ViteManifest {
2827
const manifest = vscode.Uri.joinPath(root, 'build.manifest.json').fsPath;
@@ -37,25 +36,11 @@ export function findRootEntry(manifest: ViteManifest): ViteManifestEntry {
3736
return { source: entry[0], chunk: entry[1] };
3837
}
3938

40-
export function findEditorWorkerWrapperChunk(manifest: ViteManifest): ViteManifestChunk | undefined {
41-
return Object.entries(manifest).find(entry => entry[0].endsWith(EDITOR_WORKER_ENTRY))?.[1];
42-
}
43-
4439
export function findRootHtml(appPath: vscode.Uri, manifest: ViteManifest): vscode.Uri {
4540
const rootEntry = findRootEntry(manifest);
4641
return vscode.Uri.joinPath(appPath, rootEntry.chunk.src ?? rootEntry.source);
4742
}
4843

49-
export function findEditorWorker(appPath: vscode.Uri, manifest: ViteManifest): vscode.Uri | undefined {
50-
// Finding the location of the editor worker is a bit tricky as Vite automatically generates a wrapper for it
51-
// But for web views we need the actual code so we can turn it into a blob URL later on
52-
const workerWrapper = findEditorWorkerWrapperChunk(manifest);
53-
if (!workerWrapper) {
54-
return;
55-
}
56-
// find the editor worker file that is not the wrapper
57-
const assetsDirectory = vscode.Uri.joinPath(appPath, 'assets');
58-
const assetFiles = fs.readdirSync(assetsDirectory.fsPath);
59-
const editorWorker = assetFiles.find(fileName => fileName.includes('editor.worker') && !workerWrapper.file.includes(fileName));
60-
return editorWorker ? vscode.Uri.joinPath(assetsDirectory, editorWorker) : undefined;
44+
export function findEditorWorker(rootPath: vscode.Uri): vscode.Uri | undefined {
45+
return vscode.Uri.joinPath(rootPath, 'assets', 'monaco-workers', 'editor.js');
6146
}

extension/src/editors/webview-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const createWebViewContent = (
5353
}
5454

5555
// script to set the editor worker location, needed to load the editor worker from the webview as it only allows blob: or data: fetching
56-
const workerUri = findEditorWorker(rootPath, manifest);
56+
const workerUri = findEditorWorker(context.extensionUri);
5757
if (workerUri) {
5858
const editorWorkerLocation = webview.asWebviewUri(workerUri);
5959
const editorWorkerLocationScript = new Element('script', { nonce: nonce }, [

extension/webpack.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,21 @@ const config = {
4646
}
4747
};
4848

49-
module.exports = config;
49+
// cf. https://github.com/TypeFox/monaco-languageclient/blob/067681adb1c283bfc9a85db989e79bd06599f3a7/docs/guides/troubleshooting.md#webpack-worker-issues
50+
/**@type {import('webpack').Configuration}*/
51+
const monacoWorkerConfig = {
52+
entry: {
53+
editor: './node_modules/@codingame/monaco-vscode-editor-api/esm/vs/editor/editor.worker.js'
54+
// textmate: './node_modules/@codingame/monaco-vscode-textmate-service-override/worker.js'
55+
},
56+
output: {
57+
filename: '[name].js',
58+
path: path.resolve(__dirname, './assets/monaco-workers')
59+
},
60+
mode: 'production',
61+
performance: {
62+
hints: false
63+
}
64+
};
65+
66+
module.exports = [config, monacoWorkerConfig];

pnpm-lock.yaml

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

webviews/process-editor/package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,24 @@
1616
"url": "https://github.com/axonivy/process-editor"
1717
},
1818
"dependencies": {
19-
"@axonivy/process-editor": "~13.2.0-next.1853.34378948",
20-
"@axonivy/process-editor-inscription": "~13.2.0-next.1853.34378948",
21-
"@axonivy/process-editor-inscription-view": "~13.2.0-next.1853.34378948",
22-
"@axonivy/process-editor-protocol": "~13.2.0-next.1853.34378948",
19+
"@axonivy/process-editor": "~13.2.0-next.1899.1a3079bf",
20+
"@axonivy/process-editor-inscription": "~13.2.0-next.1899.1a3079bf",
21+
"@axonivy/process-editor-inscription-view": "~13.2.0-next.1899.1a3079bf",
22+
"@axonivy/process-editor-protocol": "~13.2.0-next.1899.1a3079bf",
2323
"@axonivy/vscode-webview-common": "workspace:~13.2.0-next",
24-
"@codingame/monaco-vscode-editor-service-override": "1.83.3",
25-
"@codingame/monaco-vscode-languages-service-override": "1.83.3",
26-
"@codingame/monaco-vscode-model-service-override": "1.83.3",
27-
"@codingame/monaco-vscode-api": "1.83.3",
2824
"@eclipse-glsp/client": "2.5.0",
2925
"@eclipse-glsp/vscode-integration": "2.5.0",
3026
"@eclipse-glsp/vscode-integration-webview": "2.5.0",
3127
"inversify": "6.2.2",
32-
"monaco-editor": "0.44.0",
3328
"vscode-messenger-webview": "0.4.5",
34-
"vscode-messenger-common": "0.4.5"
29+
"vscode-messenger-common": "0.4.5",
30+
"@codingame/monaco-vscode-extension-api": "^23.1.1",
31+
"vscode": "npm:@codingame/monaco-vscode-extension-api",
32+
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api"
3533
},
3634
"devDependencies": {
3735
"@vscode/codicons": "0.0.43",
36+
"@axonivy/monaco-vite-plugin": "13.2.0-next.1899.1a3079bf",
3837
"path-browserify": "1.0.1"
3938
},
4039
"type": "module",

webviews/process-editor/src/app.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import '../css/colors.css';
44
import '../css/diagram.css';
55

66
import {
7-
createIvyDiagramContainer,
87
IVY_ACCESSIBILITY_MODULES,
8+
createIvyDiagramContainer,
99
ivyBreakpointModule,
1010
ivyOpenDataClassModule,
1111
ivyOpenFormModule,
@@ -77,31 +77,29 @@ async function initMonaco(): Promise<unknown> {
7777
//
7878
// So what we do instead is to expose the editor worker location as Webview Uri in our IvyEditorProvider and store it in the 'editorWorkerLocation' variable.
7979
// We then fetch the script stored at that location and translate it into a blob as blob and data URLs are supported for workers.
80-
//
81-
// Packaging with Vite has it's own handling of web workers so it can be properly accessed without any custom configuration.
82-
// We therefore trigger the generation of the necessary script file here through the import so that we can later expose the generated file under the
83-
// 'editorWorkerLocation' variable:
84-
import('monaco-editor/esm/vs/editor/editor.worker?worker');
85-
8680
if (!editorWorkerLocation) {
8781
console.warn('Could not find editor worker location for web worker creation. Initialize without dedicated web worker support.');
88-
return MonacoEditorUtil.configureInstance({ theme: 'light', worker: { skip: true } });
82+
return MonacoEditorUtil.configureMonaco({ theme: 'light' });
8983
}
9084
try {
85+
console.info('Translate editor worker script from webview uri to blob: ' + editorWorkerLocation);
9186
const script = await fetch(editorWorkerLocation);
9287
if (script.status === 404) {
9388
throw Error('File not found ' + editorWorkerLocation);
9489
}
9590
const blob = await script.blob();
9691
class BlobWorker extends Worker {
97-
constructor(workerId?: string, label?: string, url = URL.createObjectURL(blob)) {
98-
super(url, { name: workerId ?? label });
92+
constructor(name: string, url = URL.createObjectURL(blob)) {
93+
super(url, { name, type: 'module' });
9994
this.addEventListener('error', () => URL.revokeObjectURL(url));
10095
}
10196
}
102-
return MonacoEditorUtil.configureInstance({ theme: 'light', worker: { workerConstructor: BlobWorker } });
97+
return MonacoEditorUtil.configureMonaco({
98+
theme: 'light',
99+
workerLoaders: { TextEditorWorker: () => new BlobWorker('TextEditorWorker') }
100+
});
103101
} catch (error) {
104102
console.error('Problem with retrieving the editor worker script. Initialize without dedicated web worker support.', error);
105-
return MonacoEditorUtil.configureInstance({ theme: 'light', worker: { skip: true } });
103+
return MonacoEditorUtil.configureMonaco({ theme: 'light' });
106104
}
107105
}
Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,24 @@
1+
import monacoConfigPlugin from '@axonivy/monaco-vite-plugin';
12
import { defineConfig } from 'vite';
23
import tsconfigPaths from 'vite-tsconfig-paths';
34

45
export default defineConfig(() => {
56
const config = {
6-
plugins: [tsconfigPaths()],
7+
plugins: [tsconfigPaths(), monacoConfigPlugin()],
78
build: {
89
manifest: 'build.manifest.json',
910
outDir: '../../extension/dist/webviews/process-editor',
10-
chunkSizeWarningLimit: 5000,
11-
rollupOptions: {
12-
output: {
13-
manualChunks(id: string) {
14-
if (id.includes('monaco-languageclient' || id.includes('vscode'))) {
15-
return 'monaco-chunk';
16-
}
17-
}
18-
}
19-
}
11+
chunkSizeWarningLimit: 5000
2012
},
2113
server: {
2214
port: 3000,
2315
open: false,
24-
sourcemapIgnoreList(sourcePath, sourcemapPath) {
16+
sourcemapIgnoreList(sourcePath: string, sourcemapPath: string) {
2517
return sourcePath.includes('node_modules') && !sourcePath.includes('@eclipse-glsp') && !sourcePath.includes('@axonivy');
2618
}
2719
},
2820
resolve: { alias: { path: 'path-browserify' } },
29-
base: './',
30-
optimizeDeps: {
31-
needsInterop: [
32-
'monaco-editor/esm/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.js',
33-
'monaco-editor/esm/vs/editor/standalone/browser/inspectTokens/inspectTokens.js'
34-
]
35-
}
21+
base: './'
3622
};
3723
return config;
3824
});

0 commit comments

Comments
 (0)