
import '../vscode/src/vs/editor/common/services/editorWebWorkerMain.js';
import { start } from '../vscode/src/vs/editor/editor.worker.start.js';

function initialize(createFn) {
    start((context) => {
        let requestHandler;
        return new Proxy({}, {
            get(_target, propKey) {
                if (propKey === '$initialize') {
                    return async (data) => {
                        if (!requestHandler) {
                            requestHandler = createFn(context, data);
                        }
                    };
                }
                const value = requestHandler?.[propKey];
                if (typeof value === 'function') {
                    return value.bind(requestHandler);
                }
                return value;
            }
        });
    });
}

export { initialize };
