"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GrammarsContributionPoint = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_core_common_1 = require("@opensumi/ide-core-common");
const tokenizer_1 = require("@opensumi/ide-monaco/lib/browser/contrib/tokenizer");
const common_1 = require("../../../common");
const types_1 = require("../../types");
let GrammarsContributionPoint = class GrammarsContributionPoint extends common_1.VSCodeContributePoint {
    contribute() {
        for (const contrib of this.contributesMap) {
            const { extensionId, contributes } = contrib;
            const extension = this.extensionManageService.getExtensionInstanceByExtId(extensionId);
            if (!extension) {
                continue;
            }
            for (const grammar of contributes) {
                this.textMateService.registerGrammar(grammar, ide_core_common_1.URI.from(extension.uri));
                this.addDispose(ide_core_common_1.Disposable.create(() => {
                    this.textMateService.unregisterGrammar(grammar);
                }));
            }
        }
    }
};
exports.GrammarsContributionPoint = GrammarsContributionPoint;
GrammarsContributionPoint.schema = {
    description: (0, ide_core_common_1.localize)('vscode.extension.contributes.grammars', 'Contributes textmate tokenizers.'),
    type: 'array',
    defaultSnippets: [
        { body: [{ language: '${1:id}', scopeName: 'source.${2:id}', path: './syntaxes/${3:id}.tmLanguage.' }] },
    ],
    items: {
        type: 'object',
        defaultSnippets: [
            { body: { language: '${1:id}', scopeName: 'source.${2:id}', path: './syntaxes/${3:id}.tmLanguage.' } },
        ],
        properties: {
            language: {
                description: (0, ide_core_common_1.localize)('vscode.extension.contributes.grammars.language', 'Language identifier for which this syntax is contributed to.'),
                type: 'string',
            },
            scopeName: {
                description: (0, ide_core_common_1.localize)('vscode.extension.contributes.grammars.scopeName', 'Textmate scope name used by the tmLanguage file.'),
                type: 'string',
            },
            path: {
                description: (0, ide_core_common_1.localize)('vscode.extension.contributes.grammars.path', "Path of the tmLanguage file. The path is relative to the extension folder and typically starts with './syntaxes/'."),
                type: 'string',
            },
            embeddedLanguages: {
                description: (0, ide_core_common_1.localize)('vscode.extension.contributes.grammars.embeddedLanguages', 'A map of scope name to language id if this grammar contains embedded languages.'),
                type: 'object',
            },
            tokenTypes: {
                description: (0, ide_core_common_1.localize)('vscode.extension.contributes.grammars.tokenTypes', 'A map of scope name to token types.'),
                type: 'object',
                additionalProperties: {
                    enum: ['string', 'comment', 'other'],
                },
            },
            injectTo: {
                description: (0, ide_core_common_1.localize)('vscode.extension.contributes.grammars.injectTo', 'List of language scope names to which this grammar is injected to.'),
                type: 'array',
                items: {
                    type: 'string',
                },
            },
        },
        required: ['scopeName', 'path'],
    },
};
tslib_1.__decorate([
    (0, di_1.Autowired)(tokenizer_1.ITextmateTokenizer),
    tslib_1.__metadata("design:type", Object)
], GrammarsContributionPoint.prototype, "textMateService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(types_1.AbstractExtInstanceManagementService),
    tslib_1.__metadata("design:type", types_1.AbstractExtInstanceManagementService)
], GrammarsContributionPoint.prototype, "extensionManageService", void 0);
exports.GrammarsContributionPoint = GrammarsContributionPoint = tslib_1.__decorate([
    (0, di_1.Injectable)(),
    (0, common_1.Contributes)('grammars'),
    (0, common_1.LifeCycle)(2 /* LifeCyclePhase.Initialize */)
], GrammarsContributionPoint);
//# sourceMappingURL=grammar.js.map