"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtCommandManagementImpl = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_core_common_1 = require("@opensumi/ide-core-common");
/**
 * 管理插件命令的运行环境
 */
let ExtCommandManagementImpl = class ExtCommandManagementImpl extends ide_core_common_1.Disposable {
    constructor() {
        super(...arguments);
        /**
         * 存储插件的 command 的注册环境
         */
        this.commandEnvRegistry = new Map();
        /**
         * 存储不同执行环境的 command 的 executor
         */
        this.proxyCommandExecutorRegistry = new Map();
    }
    dispose() {
        this.commandEnvRegistry.clear();
        this.proxyCommandExecutorRegistry.clear();
    }
    registerProxyCommandExecutor(env, proxyCommandExecutor) {
        this.proxyCommandExecutorRegistry.set(env, proxyCommandExecutor);
    }
    async executeExtensionCommand(env, command, args) {
        const targetProxyCommandExecutor = this.proxyCommandExecutorRegistry.get(env);
        if (!targetProxyCommandExecutor) {
            throw new Error('Proxy command executor "' + env + '" is not existed');
        }
        return targetProxyCommandExecutor.$executeExtensionCommand(command, ...args);
    }
    /**
     * 标记 command 的运行环境
     */
    registerExtensionCommandEnv(command, targetHost = 'node') {
        this.commandEnvRegistry.set(command, targetHost);
        return {
            dispose: () => {
                this.commandEnvRegistry.delete(command);
            },
        };
    }
    getExtensionCommandEnv(command) {
        return this.commandEnvRegistry.get(command);
    }
};
exports.ExtCommandManagementImpl = ExtCommandManagementImpl;
exports.ExtCommandManagementImpl = ExtCommandManagementImpl = tslib_1.__decorate([
    (0, di_1.Injectable)()
], ExtCommandManagementImpl);
//# sourceMappingURL=extension-command-management.js.map