"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("regenerator-runtime/runtime.js");

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

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

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

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

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.FileType = exports.FsReadDirRequest = exports.FsStatRequest = void 0;
exports.getFileSystemProvider = getFileSystemProvider;

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

var FsStatRequest;

(function (FsStatRequest) {
  FsStatRequest.type = new vscode_languageserver_1.RequestType('fs/stat');
})(FsStatRequest || (exports.FsStatRequest = FsStatRequest = {}));

var FsReadDirRequest;

(function (FsReadDirRequest) {
  FsReadDirRequest.type = new vscode_languageserver_1.RequestType('fs/readDir');
})(FsReadDirRequest || (exports.FsReadDirRequest = FsReadDirRequest = {}));

var FileType;

(function (FileType) {
  /**
   * The file type is unknown.
   */
  FileType[FileType["Unknown"] = 0] = "Unknown";
  /**
   * A regular file.
   */

  FileType[FileType["File"] = 1] = "File";
  /**
   * A directory.
   */

  FileType[FileType["Directory"] = 2] = "Directory";
  /**
   * A symbolic link to a file.
   */

  FileType[FileType["SymbolicLink"] = 64] = "SymbolicLink";
})(FileType || (exports.FileType = FileType = {}));

function getFileSystemProvider(handledSchemas, connection, runtime) {
  var fileFs = runtime.fileFs && handledSchemas.indexOf('file') !== -1 ? runtime.fileFs : undefined;
  return {
    stat: function stat(uri) {
      return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
        var res;
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                if (!(fileFs && uri.startsWith('file:'))) {
                  _context.next = 2;
                  break;
                }

                return _context.abrupt("return", fileFs.stat(uri));

              case 2:
                _context.next = 4;
                return connection.sendRequest(FsStatRequest.type, uri.toString());

              case 4:
                res = _context.sent;
                return _context.abrupt("return", res);

              case 6:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }))();
    },
    readDirectory: function readDirectory(uri) {
      if (fileFs && uri.startsWith('file:')) {
        return fileFs.readDirectory(uri);
      }

      return connection.sendRequest(FsReadDirRequest.type, uri.toString());
    }
  };
}