"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProblemMatchersContributionPoint = exports.problemMatchersSchema = exports.Schemas = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_core_common_1 = require("@opensumi/ide-core-common");
const common_1 = require("../../../common");
const problemPatterns_1 = require("./problemPatterns");
const { deepClone } = ide_core_common_1.objects;
var Schemas;
(function (Schemas) {
    Schemas.WatchingPattern = {
        type: 'object',
        additionalProperties: false,
        properties: {
            regexp: {
                type: 'string',
                description: (0, ide_core_common_1.localize)('WatchingPatternSchema.regexp', 'The regular expression to detect the begin or end of a background task.'),
            },
            file: {
                type: 'integer',
                description: (0, ide_core_common_1.localize)('WatchingPatternSchema.file', 'The match group index of the filename. Can be omitted.'),
            },
        },
    };
    Schemas.PatternType = {
        anyOf: [
            {
                type: 'string',
                description: (0, ide_core_common_1.localize)('PatternTypeSchema.name', 'The name of a contributed or predefined pattern'),
            },
            problemPatterns_1.PatternSchemas.ProblemPattern,
            problemPatterns_1.PatternSchemas.MultiLineProblemPattern,
        ],
        description: (0, ide_core_common_1.localize)('PatternTypeSchema.description', 'A problem pattern or the name of a contributed or predefined problem pattern. Can be omitted if base is specified.'),
    };
    Schemas.ProblemMatcher = {
        type: 'object',
        additionalProperties: false,
        properties: {
            base: {
                type: 'string',
                description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.base', 'The name of a base problem matcher to use.'),
            },
            owner: {
                type: 'string',
                description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.owner', "The owner of the problem inside Code. Can be omitted if base is specified. Defaults to 'external' if omitted and base is not specified."),
            },
            source: {
                type: 'string',
                description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.source', "A human-readable string describing the source of this diagnostic, e.g. 'typescript' or 'super lint'."),
            },
            severity: {
                type: 'string',
                enum: ['error', 'warning', 'info'],
                description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.severity', "The default severity for captures problems. Is used if the pattern doesn't define a match group for severity."),
            },
            applyTo: {
                type: 'string',
                enum: ['allDocuments', 'openDocuments', 'closedDocuments'],
                description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.applyTo', 'Controls if a problem reported on a text document is applied only to open, closed or all documents.'),
            },
            pattern: Schemas.PatternType,
            fileLocation: {
                oneOf: [
                    {
                        type: 'string',
                        enum: ['absolute', 'relative', 'autoDetect'],
                    },
                    {
                        type: 'array',
                        items: {
                            type: 'string',
                        },
                    },
                ],
                description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.fileLocation', 'Defines how file names reported in a problem pattern should be interpreted.'),
            },
            background: {
                type: 'object',
                additionalProperties: false,
                description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.background', 'Patterns to track the begin and end of a matcher active on a background task.'),
                properties: {
                    activeOnStart: {
                        type: 'boolean',
                        description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.background.activeOnStart', 'If set to true the background monitor is in active mode when the task starts. This is equals of issuing a line that matches the beginsPattern'),
                    },
                    beginsPattern: {
                        oneOf: [
                            {
                                type: 'string',
                            },
                            Schemas.WatchingPattern,
                        ],
                        description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.background.beginsPattern', 'If matched in the output the start of a background task is signaled.'),
                    },
                    endsPattern: {
                        oneOf: [
                            {
                                type: 'string',
                            },
                            Schemas.WatchingPattern,
                        ],
                        description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.background.endsPattern', 'If matched in the output the end of a background task is signaled.'),
                    },
                },
            },
            watching: {
                type: 'object',
                additionalProperties: false,
                deprecationMessage: (0, ide_core_common_1.localize)('ProblemMatcherSchema.watching.deprecated', 'The watching property is deprecated. Use background instead.'),
                description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.watching', 'Patterns to track the begin and end of a watching matcher.'),
                properties: {
                    activeOnStart: {
                        type: 'boolean',
                        description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.watching.activeOnStart', 'If set to true the watcher is in active mode when the task starts. This is equals of issuing a line that matches the beginPattern'),
                    },
                    beginsPattern: {
                        oneOf: [
                            {
                                type: 'string',
                            },
                            Schemas.WatchingPattern,
                        ],
                        description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.watching.beginsPattern', 'If matched in the output the start of a watching task is signaled.'),
                    },
                    endsPattern: {
                        oneOf: [
                            {
                                type: 'string',
                            },
                            Schemas.WatchingPattern,
                        ],
                        description: (0, ide_core_common_1.localize)('ProblemMatcherSchema.watching.endsPattern', 'If matched in the output the end of a watching task is signaled.'),
                    },
                },
            },
        },
    };
    Schemas.LegacyProblemMatcher = deepClone(Schemas.ProblemMatcher);
    Schemas.LegacyProblemMatcher.properties = deepClone(Schemas.LegacyProblemMatcher.properties) || {};
    Schemas.LegacyProblemMatcher.properties['watchedTaskBeginsRegExp'] = {
        type: 'string',
        deprecationMessage: (0, ide_core_common_1.localize)('LegacyProblemMatcherSchema.watchedBegin.deprecated', 'This property is deprecated. Use the watching property instead.'),
        description: (0, ide_core_common_1.localize)('LegacyProblemMatcherSchema.watchedBegin', 'A regular expression signaling that a watched tasks begins executing triggered through file watching.'),
    };
    Schemas.LegacyProblemMatcher.properties['watchedTaskEndsRegExp'] = {
        type: 'string',
        deprecationMessage: (0, ide_core_common_1.localize)('LegacyProblemMatcherSchema.watchedEnd.deprecated', 'This property is deprecated. Use the watching property instead.'),
        description: (0, ide_core_common_1.localize)('LegacyProblemMatcherSchema.watchedEnd', 'A regular expression signaling that a watched tasks ends executing.'),
    };
    Schemas.NamedProblemMatcher = deepClone(Schemas.ProblemMatcher);
    Schemas.NamedProblemMatcher.properties = deepClone(Schemas.NamedProblemMatcher.properties) || {};
    Schemas.NamedProblemMatcher.properties.name = {
        type: 'string',
        description: (0, ide_core_common_1.localize)('NamedProblemMatcherSchema.name', 'The name of the problem matcher used to refer to it.'),
    };
    Schemas.NamedProblemMatcher.properties.label = {
        type: 'string',
        description: (0, ide_core_common_1.localize)('NamedProblemMatcherSchema.label', 'A human readable label of the problem matcher.'),
    };
})(Schemas || (exports.Schemas = Schemas = {}));
exports.problemMatchersSchema = {
    description: (0, ide_core_common_1.localize)('ProblemMatcherExtPoint', 'Contributes problem matchers'),
    type: 'array',
    items: Schemas.NamedProblemMatcher,
};
let ProblemMatchersContributionPoint = class ProblemMatchersContributionPoint extends common_1.VSCodeContributePoint {
    contribute() {
        for (const contrib of this.contributesMap) {
            const { contributes } = contrib;
            for (const matcher of contributes) {
                this.addDispose(this.problemMatcher.register(matcher));
            }
        }
    }
};
exports.ProblemMatchersContributionPoint = ProblemMatchersContributionPoint;
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_core_common_1.IProblemMatcherRegistry),
    tslib_1.__metadata("design:type", Object)
], ProblemMatchersContributionPoint.prototype, "problemMatcher", void 0);
exports.ProblemMatchersContributionPoint = ProblemMatchersContributionPoint = tslib_1.__decorate([
    (0, di_1.Injectable)(),
    (0, common_1.Contributes)('problemMatchers'),
    (0, common_1.LifeCycle)(4 /* LifeCyclePhase.Ready */)
], ProblemMatchersContributionPoint);
//# sourceMappingURL=problemMatchers.js.map