"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandsContributionPoint = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const ide_theme_1 = require("@opensumi/ide-theme");
const common_1 = require("../../../common");
const types_1 = require("../../types");
let CommandsContributionPoint = class CommandsContributionPoint extends common_1.VSCodeContributePoint {
    contribute() {
        for (const contrib of this.contributesMap) {
            const { extensionId, contributes } = contrib;
            const extension = this.extensionManageService.getExtensionInstanceByExtId(extensionId);
            if (!extension) {
                continue;
            }
            contributes.forEach((command) => {
                this.addDispose(this.commandRegistry.registerCommand({
                    category: this.getLocalizeFromNlsJSON(command.category, extensionId),
                    label: this.getLocalizeFromNlsJSON(command.title, extensionId),
                    shortLabel: command.shortTitle ? this.getLocalizeFromNlsJSON(command.shortTitle, extensionId) : undefined,
                    categoryLocalized: this.createLocalizedStr(command.category, extensionId),
                    labelLocalized: this.createLocalizedStr(command.title, extensionId),
                    shortLabelLocalized: command.shortTitle
                        ? this.createLocalizedStr(command.shortTitle, extensionId)
                        : undefined,
                    id: command.command,
                    iconClass: (typeof command.icon === 'string' && this.iconService.fromString(command.icon)) ||
                        this.iconService.fromIcon(extension.path, command.icon, ide_theme_1.IconType.Background),
                    enablement: command.enablement,
                }, {
                    execute: (...args) => this.extensionService.executeExtensionCommand(command.command, args),
                }));
                if (this.config.noExtHost) {
                    this.addDispose(this.extensionCommandManager.registerExtensionCommandEnv(command.command, 'worker'));
                }
                else {
                    this.addDispose(this.extensionCommandManager.registerExtensionCommandEnv(command.command, 'node'));
                }
            });
        }
    }
};
exports.CommandsContributionPoint = CommandsContributionPoint;
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_core_browser_1.CommandRegistry),
    tslib_1.__metadata("design:type", Object)
], CommandsContributionPoint.prototype, "commandRegistry", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(common_1.ExtensionService),
    tslib_1.__metadata("design:type", common_1.ExtensionService)
], CommandsContributionPoint.prototype, "extensionService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(common_1.IExtCommandManagement),
    tslib_1.__metadata("design:type", common_1.IExtCommandManagement)
], CommandsContributionPoint.prototype, "extensionCommandManager", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_theme_1.IIconService),
    tslib_1.__metadata("design:type", Object)
], CommandsContributionPoint.prototype, "iconService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_core_browser_1.AppConfig),
    tslib_1.__metadata("design:type", Object)
], CommandsContributionPoint.prototype, "config", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(types_1.AbstractExtInstanceManagementService),
    tslib_1.__metadata("design:type", types_1.AbstractExtInstanceManagementService)
], CommandsContributionPoint.prototype, "extensionManageService", void 0);
exports.CommandsContributionPoint = CommandsContributionPoint = tslib_1.__decorate([
    (0, di_1.Injectable)(),
    (0, common_1.Contributes)('commands'),
    (0, common_1.LifeCycle)(3 /* LifeCyclePhase.Starting */)
], CommandsContributionPoint);
//# sourceMappingURL=commands.js.map