"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Diagnostics = void 0;
class Diagnostics {
    constructor(connection, documentService, parserService, linterService) {
        this.diagnostics = new Map();
        this.connection = connection;
        this.documentService = documentService;
        this.parserService = parserService;
        this.linterService = linterService;
    }
    async validate(textDocument) {
        const parseResult = this.parserService.parseDocument(textDocument);
        const lintResult = await this.linterService.lintDocument(parseResult.document, textDocument);
        const allDiagnostics = [
            ...parseResult.diagnostics,
            ...lintResult.diagnostics,
        ];
        this.diagnostics.set(textDocument, allDiagnostics);
        this.sendDiagnosticsFor(textDocument);
    }
    async refreshDocument(document) {
        await this.validate(document);
    }
    async refreshAllDocuments() {
        const documents = this.documentService.getAll();
        await Promise.all(documents.map(document => this.refreshDocument(document)));
    }
    sendDiagnosticsFor(textDocument) {
        const diagnostics = this.diagnostics.get(textDocument) || [];
        this.connection.sendDiagnostics({
            uri: textDocument.uri,
            diagnostics,
        });
        this.diagnostics.delete(textDocument);
    }
}
exports.Diagnostics = Diagnostics;
//# sourceMappingURL=diagnostics.js.map