"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

require("core-js/modules/es.array.slice.js");

require("core-js/modules/es.function.name.js");

require("core-js/modules/es.array.from.js");

require("core-js/modules/es.string.iterator.js");

require("core-js/modules/es.regexp.exec.js");

require("core-js/modules/es.symbol.js");

require("core-js/modules/es.symbol.description.js");

require("core-js/modules/es.symbol.iterator.js");

require("core-js/modules/es.array.iterator.js");

require("core-js/modules/web.dom-collections.iterator.js");

require("core-js/modules/es.array.map.js");

require("core-js/modules/es.object.to-string.js");

require("core-js/modules/web.dom-collections.for-each.js");

require("core-js/modules/es.promise.js");

require("regenerator-runtime/runtime.js");

function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TextDocument = exports.TokenType = exports.ClientCapabilities = exports.TextDocumentIdentifier = exports.SelectionRange = exports.DiagnosticSeverity = exports.ParameterInformation = exports.SignatureInformation = exports.WorkspaceEdit = exports.ColorPresentation = exports.ColorInformation = exports.Color = exports.TextEdit = exports.SymbolKind = exports.SymbolInformation = exports.Range = exports.Position = exports.Location = exports.Hover = exports.FormattingOptions = exports.FoldingRangeKind = exports.FoldingRange = exports.DocumentLink = exports.DocumentHighlightKind = exports.DocumentHighlight = exports.Diagnostic = exports.CompletionItemKind = exports.CompletionList = exports.CompletionItem = exports.WorkspaceFolder = void 0;
exports.isCompletionItemData = isCompletionItemData;
exports.getLanguageModes = getLanguageModes;

var vscode_css_languageservice_1 = require("vscode-css-languageservice");

var vscode_html_languageservice_1 = require("vscode-html-languageservice");

var languageModelCache_1 = require("../languageModelCache");

var cssMode_1 = require("./cssMode");

var embeddedSupport_1 = require("./embeddedSupport");

var htmlMode_1 = require("./htmlMode");

var javascriptMode_1 = require("./javascriptMode");

var vscode_languageserver_1 = require("vscode-languageserver");

Object.defineProperty(exports, "WorkspaceFolder", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.WorkspaceFolder;
  }
});
Object.defineProperty(exports, "CompletionItem", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.CompletionItem;
  }
});
Object.defineProperty(exports, "CompletionList", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.CompletionList;
  }
});
Object.defineProperty(exports, "CompletionItemKind", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.CompletionItemKind;
  }
});
Object.defineProperty(exports, "Diagnostic", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.Diagnostic;
  }
});
Object.defineProperty(exports, "DocumentHighlight", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.DocumentHighlight;
  }
});
Object.defineProperty(exports, "DocumentHighlightKind", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.DocumentHighlightKind;
  }
});
Object.defineProperty(exports, "DocumentLink", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.DocumentLink;
  }
});
Object.defineProperty(exports, "FoldingRange", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.FoldingRange;
  }
});
Object.defineProperty(exports, "FoldingRangeKind", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.FoldingRangeKind;
  }
});
Object.defineProperty(exports, "FormattingOptions", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.FormattingOptions;
  }
});
Object.defineProperty(exports, "Hover", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.Hover;
  }
});
Object.defineProperty(exports, "Location", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.Location;
  }
});
Object.defineProperty(exports, "Position", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.Position;
  }
});
Object.defineProperty(exports, "Range", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.Range;
  }
});
Object.defineProperty(exports, "SymbolInformation", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.SymbolInformation;
  }
});
Object.defineProperty(exports, "SymbolKind", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.SymbolKind;
  }
});
Object.defineProperty(exports, "TextEdit", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.TextEdit;
  }
});
Object.defineProperty(exports, "Color", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.Color;
  }
});
Object.defineProperty(exports, "ColorInformation", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.ColorInformation;
  }
});
Object.defineProperty(exports, "ColorPresentation", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.ColorPresentation;
  }
});
Object.defineProperty(exports, "WorkspaceEdit", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.WorkspaceEdit;
  }
});
Object.defineProperty(exports, "SignatureInformation", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.SignatureInformation;
  }
});
Object.defineProperty(exports, "ParameterInformation", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.ParameterInformation;
  }
});
Object.defineProperty(exports, "DiagnosticSeverity", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.DiagnosticSeverity;
  }
});
Object.defineProperty(exports, "SelectionRange", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.SelectionRange;
  }
});
Object.defineProperty(exports, "TextDocumentIdentifier", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_1.TextDocumentIdentifier;
  }
});

var vscode_html_languageservice_2 = require("vscode-html-languageservice");

Object.defineProperty(exports, "ClientCapabilities", {
  enumerable: true,
  get: function get() {
    return vscode_html_languageservice_2.ClientCapabilities;
  }
});
Object.defineProperty(exports, "TokenType", {
  enumerable: true,
  get: function get() {
    return vscode_html_languageservice_2.TokenType;
  }
});

var vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");

Object.defineProperty(exports, "TextDocument", {
  enumerable: true,
  get: function get() {
    return vscode_languageserver_textdocument_1.TextDocument;
  }
});

function isCompletionItemData(value) {
  return value && typeof value.languageId === 'string' && typeof value.uri === 'string' && typeof value.offset === 'number';
}

function getLanguageModes(supportedLanguages, workspace, clientCapabilities, requestService) {
  var htmlLanguageService = (0, vscode_html_languageservice_1.getLanguageService)({
    clientCapabilities: clientCapabilities,
    fileSystemProvider: requestService
  });
  var cssLanguageService = (0, vscode_css_languageservice_1.getCSSLanguageService)({
    clientCapabilities: clientCapabilities,
    fileSystemProvider: requestService
  });
  var documentRegions = (0, languageModelCache_1.getLanguageModelCache)(10, 60, function (document) {
    return (0, embeddedSupport_1.getDocumentRegions)(htmlLanguageService, document);
  });
  var modelCaches = [];
  modelCaches.push(documentRegions);
  var modes = Object.create(null);
  modes['html'] = (0, htmlMode_1.getHTMLMode)(htmlLanguageService, workspace);

  if (supportedLanguages['css']) {
    modes['css'] = (0, cssMode_1.getCSSMode)(cssLanguageService, documentRegions, workspace);
  }

  if (supportedLanguages['javascript']) {
    modes['javascript'] = (0, javascriptMode_1.getJavaScriptMode)(documentRegions, 'javascript', workspace);
    modes['typescript'] = (0, javascriptMode_1.getJavaScriptMode)(documentRegions, 'typescript', workspace);
  }

  return {
    updateDataProviders: function updateDataProviders(dataProviders) {
      return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                htmlLanguageService.setDataProviders(true, dataProviders);

              case 1:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }))();
    },
    getModeAtPosition: function getModeAtPosition(document, position) {
      var languageId = documentRegions.get(document).getLanguageAtPosition(position);

      if (languageId) {
        return modes[languageId];
      }

      return undefined;
    },
    getModesInRange: function getModesInRange(document, range) {
      return documentRegions.get(document).getLanguageRanges(range).map(function (r) {
        return {
          start: r.start,
          end: r.end,
          mode: r.languageId && modes[r.languageId],
          attributeValue: r.attributeValue
        };
      });
    },
    getAllModesInDocument: function getAllModesInDocument(document) {
      var result = [];

      var _iterator = _createForOfIteratorHelper(documentRegions.get(document).getLanguagesInDocument()),
          _step;

      try {
        for (_iterator.s(); !(_step = _iterator.n()).done;) {
          var languageId = _step.value;
          var mode = modes[languageId];

          if (mode) {
            result.push(mode);
          }
        }
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }

      return result;
    },
    getAllModes: function getAllModes() {
      var result = [];

      for (var languageId in modes) {
        var mode = modes[languageId];

        if (mode) {
          result.push(mode);
        }
      }

      return result;
    },
    getMode: function getMode(languageId) {
      return modes[languageId];
    },
    onDocumentRemoved: function onDocumentRemoved(document) {
      modelCaches.forEach(function (mc) {
        return mc.onDocumentRemoved(document);
      });

      for (var mode in modes) {
        modes[mode].onDocumentRemoved(document);
      }
    },
    dispose: function dispose() {
      modelCaches.forEach(function (mc) {
        return mc.dispose();
      });
      modelCaches = [];

      for (var mode in modes) {
        modes[mode].dispose();
      }

      modes = {};
    }
  };
}