"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const lifecycle = require("../../../base/common/lifecycle.js");
const strings = require("../../../base/common/strings.js");
const uri = require("../../../base/common/uri.js");
const instantiation = require("../../instantiation/common/instantiation.js");
var __awaiter = globalThis && globalThis.__awaiter || function(thisArg, _arguments, P, generator) {
  function adopt(value) {
    return value instanceof P ? value : new P(function(resolve) {
      resolve(value);
    });
  }
  return new (P || (P = Promise))(function(resolve, reject) {
    function fulfilled(value) {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    }
    function rejected(value) {
      try {
        step(generator["throw"](value));
      } catch (e) {
        reject(e);
      }
    }
    function step(result) {
      result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
    }
    step((generator = generator.apply(thisArg, _arguments || [])).next());
  });
};
const IOpenerService = instantiation.createDecorator("openerService");
const NullOpenerService = Object.freeze({
  _serviceBrand: void 0,
  registerOpener() {
    return lifecycle.Disposable.None;
  },
  registerValidator() {
    return lifecycle.Disposable.None;
  },
  registerExternalUriResolver() {
    return lifecycle.Disposable.None;
  },
  setDefaultExternalOpener() {
  },
  registerExternalOpener() {
    return lifecycle.Disposable.None;
  },
  open() {
    return __awaiter(this, void 0, void 0, function* () {
      return false;
    });
  },
  resolveExternalUri(uri2) {
    return __awaiter(this, void 0, void 0, function* () {
      return { resolved: uri2, dispose() {
      } };
    });
  }
});
function matchesScheme(target, scheme) {
  if (uri.URI.isUri(target)) {
    return strings.equalsIgnoreCase(target.scheme, scheme);
  } else {
    return strings.startsWithIgnoreCase(target, scheme + ":");
  }
}
function matchesSomeScheme(target, ...schemes) {
  return schemes.some((scheme) => matchesScheme(target, scheme));
}
function extractSelection(uri2) {
  let selection = void 0;
  const match = /^L?(\d+)(?:,(\d+))?(-L?(\d+)(?:,(\d+))?)?/.exec(uri2.fragment);
  if (match) {
    selection = {
      startLineNumber: parseInt(match[1]),
      startColumn: match[2] ? parseInt(match[2]) : 1,
      endLineNumber: match[4] ? parseInt(match[4]) : void 0,
      endColumn: match[4] ? match[5] ? parseInt(match[5]) : 1 : void 0
    };
    uri2 = uri2.with({ fragment: "" });
  }
  return { selection, uri: uri2 };
}
exports.IOpenerService = IOpenerService;
exports.NullOpenerService = NullOpenerService;
exports.extractSelection = extractSelection;
exports.matchesScheme = matchesScheme;
exports.matchesSomeScheme = matchesSomeScheme;
