var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "@vscode/l10n", "vscode-languageserver", "vscode-languageserver/browser", "../languageserver/telemetry", "../languageservice/services/schemaRequestHandler", "../yamlServerInit", "../yamlSettings"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    /*---------------------------------------------------------------------------------------------
     *  Copyright (c) Red Hat, Inc. All rights reserved.
     *  Copyright (c) Microsoft Corporation. All rights reserved.
     *  Licensed under the MIT License. See License.txt in the project root for license information.
     *--------------------------------------------------------------------------------------------*/
    const l10n = __importStar(require("@vscode/l10n"));
    const vscode_languageserver_1 = require("vscode-languageserver");
    const browser_1 = require("vscode-languageserver/browser");
    const telemetry_1 = require("../languageserver/telemetry");
    const schemaRequestHandler_1 = require("../languageservice/services/schemaRequestHandler");
    const yamlServerInit_1 = require("../yamlServerInit");
    const yamlSettings_1 = require("../yamlSettings");
    // eslint-disable-next-line @typescript-eslint/no-namespace
    var FSReadFile;
    (function (FSReadFile) {
        FSReadFile.type = new vscode_languageserver_1.RequestType('fs/readFile');
    })(FSReadFile || (FSReadFile = {}));
    self.onmessage = (e) => {
        const messageReader = new browser_1.BrowserMessageReader(globalThis);
        const messageWriter = new browser_1.BrowserMessageWriter(globalThis);
        const connection = (0, browser_1.createConnection)(messageReader, messageWriter);
        const yamlSettings = new yamlSettings_1.SettingsState();
        const fileSystem = {
            readFile: (fsPath) => {
                return connection.sendRequest(FSReadFile.type, fsPath);
            },
        };
        /**
         * Handles schema content requests given the schema URI
         * @param uri can be a local file, vscode request, http(s) request or a custom request
         */
        const schemaRequestHandlerWrapper = (connection, uri) => {
            return (0, schemaRequestHandler_1.schemaRequestHandler)(connection, uri, yamlSettings.workspaceFolders, yamlSettings.workspaceRoot, yamlSettings.useVSCodeContentRequest, fileSystem, true);
        };
        const schemaRequestService = schemaRequestHandlerWrapper.bind(this, connection);
        const telemetry = new telemetry_1.TelemetryImpl(connection);
        l10n.config({ contents: e.data.l10nBundle });
        new yamlServerInit_1.YAMLServerInit(connection, yamlSettings, schemaRequestHandler_1.workspaceContext, schemaRequestService, telemetry).start();
    };
});
//# sourceMappingURL=yamlServerMain.js.map