"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SemanticTokenScopesContributionPoint = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const log_1 = require("@opensumi/ide-core-common/lib/log");
const semantic_tokens_registry_1 = require("@opensumi/ide-theme/lib/common/semantic-tokens-registry");
const common_1 = require("../../../common");
let SemanticTokenScopesContributionPoint = class SemanticTokenScopesContributionPoint extends common_1.VSCodeContributePoint {
    contribute() {
        for (const contrib of this.contributesMap) {
            const { contributes } = contrib;
            if (!Array.isArray(contributes)) {
                this.logger.warn("'configuration.semanticTokenScopes' must be an array");
                return;
            }
            for (const contrib of contributes) {
                if (!contrib.scopes || typeof contrib.scopes !== 'object') {
                    this.logger.warn("'configuration.semanticTokenScopes.scopes' must be defined as an object");
                    continue;
                }
                if (contrib.language && typeof contrib.language !== 'string') {
                    this.logger.warn("'configuration.semanticTokenScopes.language' must be as a string");
                    continue;
                }
                // eslint-disable-next-line guard-for-in
                for (const selector in contrib.scopes) {
                    const scopes = contrib.scopes[selector];
                    if (!Array.isArray(scopes) || scopes.some((l) => typeof l !== 'string')) {
                        this.logger.error("'configuration.semanticTokenScopes.scopes' values must be an array of strings");
                        continue;
                    }
                    try {
                        const parsedSelector = this.semanticTokenRegistry.parseTokenSelector(selector, contrib.language);
                        this.semanticTokenRegistry.registerTokenStyleDefault(parsedSelector, {
                            scopesToProbe: scopes.map((s) => s.split(' ')),
                        });
                    }
                    catch (err) {
                        this.logger.error(`configuration.semanticTokenScopes.scopes': Problems parsing selector ${selector}.`);
                    }
                }
            }
        }
    }
};
exports.SemanticTokenScopesContributionPoint = SemanticTokenScopesContributionPoint;
tslib_1.__decorate([
    (0, di_1.Autowired)(log_1.ILogger),
    tslib_1.__metadata("design:type", Object)
], SemanticTokenScopesContributionPoint.prototype, "logger", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(semantic_tokens_registry_1.ISemanticTokenRegistry),
    tslib_1.__metadata("design:type", Object)
], SemanticTokenScopesContributionPoint.prototype, "semanticTokenRegistry", void 0);
exports.SemanticTokenScopesContributionPoint = SemanticTokenScopesContributionPoint = tslib_1.__decorate([
    (0, di_1.Injectable)(),
    (0, common_1.Contributes)('semanticTokenScopes'),
    (0, common_1.LifeCycle)(4 /* LifeCyclePhase.Ready */)
], SemanticTokenScopesContributionPoint);
//# sourceMappingURL=semanticTokenScopes.js.map