Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/editor.worker.start.ts
3291 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { initialize } from '../base/common/worker/webWorkerBootstrap.js';
7
import { EditorWorker, IWorkerContext } from './common/services/editorWebWorker.js';
8
import { EditorWorkerHost } from './common/services/editorWorkerHost.js';
9
10
/**
11
* Used by `monaco-editor` to hook up web worker rpc.
12
* @skipMangle
13
* @internal
14
*/
15
export function start<THost extends object, TClient extends object>(createClient: (ctx: IWorkerContext<THost>) => TClient): TClient {
16
let client: TClient | undefined;
17
const webWorkerServer = initialize((workerServer) => {
18
const editorWorkerHost = EditorWorkerHost.getChannel(workerServer);
19
20
const host = new Proxy({}, {
21
get(target, prop, receiver) {
22
if (prop === 'then') {
23
// Don't forward the call when the proxy is returned in an async function and the runtime tries to .then it.
24
return undefined;
25
}
26
if (typeof prop !== 'string') {
27
throw new Error(`Not supported`);
28
}
29
return (...args: unknown[]) => {
30
return editorWorkerHost.$fhr(prop, args);
31
};
32
}
33
});
34
35
const ctx: IWorkerContext<THost> = {
36
host: host as THost,
37
getMirrorModels: () => {
38
return webWorkerServer.requestHandler.getModels();
39
}
40
};
41
42
client = createClient(ctx);
43
44
return new EditorWorker(client);
45
});
46
47
return client!;
48
}
49
50