"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinterService = void 0;
const node_1 = require("vscode-languageserver/node");
const linter_1 = require("@herb-tools/linter");
class LinterService {
    constructor(settings) {
        this.source = "Herb Linter ";
        this.settings = settings;
        this.linter = new linter_1.Linter();
    }
    async lintDocument(document, textDocument) {
        var _a, _b;
        const settings = await this.settings.getDocumentSettings(textDocument.uri);
        const linterEnabled = (_b = (_a = settings.linter) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true;
        if (!linterEnabled) {
            return { diagnostics: [] };
        }
        const lintResult = this.linter.lint(document);
        const diagnostics = [];
        lintResult.offenses.forEach(offense => {
            const severity = offense.severity === "error"
                ? node_1.DiagnosticSeverity.Error
                : node_1.DiagnosticSeverity.Warning;
            const range = node_1.Range.create(node_1.Position.create(offense.location.start.line - 1, offense.location.start.column), node_1.Position.create(offense.location.end.line - 1, offense.location.end.column));
            const codeDescription = {
                href: `https://herb-tools.dev/linter/rules/${offense.rule}`
            };
            const diagnostic = {
                source: this.source,
                severity,
                range,
                message: offense.message,
                code: offense.rule,
                data: { rule: offense.rule },
                codeDescription
            };
            diagnostics.push(diagnostic);
        });
        return { diagnostics };
    }
}
exports.LinterService = LinterService;
//# sourceMappingURL=linter_service.js.map