"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const cancellation = require("../../../../base/common/cancellation.js");
const errors = require("../../../../base/common/errors.js");
const types = require("../../../../base/common/types.js");
const uri = require("../../../../base/common/uri.js");
const position = require("../../../common/core/position.js");
const languages = require("../../../common/languages.js");
const resolverService = require("../../../common/services/resolverService.js");
const commands = require("../../../../platform/commands/common/commands.js");
const contextkey = require("../../../../platform/contextkey/common/contextkey.js");
const languageFeatures = require("../../../common/services/languageFeatures.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 Context = {
  Visible: new contextkey.RawContextKey("parameterHintsVisible", false),
  MultipleSignatures: new contextkey.RawContextKey("parameterHintsMultipleSignatures", false)
};
function provideSignatureHelp(registry, model, position2, context, token) {
  return __awaiter(this, void 0, void 0, function* () {
    const supports = registry.ordered(model);
    for (const support of supports) {
      try {
        const result = yield support.provideSignatureHelp(model, position2, token, context);
        if (result) {
          return result;
        }
      } catch (err) {
        errors.onUnexpectedExternalError(err);
      }
    }
    return void 0;
  });
}
commands.CommandsRegistry.registerCommand("_executeSignatureHelpProvider", (accessor, ...args) => __awaiter(void 0, void 0, void 0, function* () {
  const [uri$1, position$1, triggerCharacter] = args;
  types.assertType(uri.URI.isUri(uri$1));
  types.assertType(position.Position.isIPosition(position$1));
  types.assertType(typeof triggerCharacter === "string" || !triggerCharacter);
  const languageFeaturesService = accessor.get(languageFeatures.ILanguageFeaturesService);
  const ref = yield accessor.get(resolverService.ITextModelService).createModelReference(uri$1);
  try {
    const result = yield provideSignatureHelp(languageFeaturesService.signatureHelpProvider, ref.object.textEditorModel, position.Position.lift(position$1), {
      triggerKind: languages.SignatureHelpTriggerKind.Invoke,
      isRetrigger: false,
      triggerCharacter
    }, cancellation.CancellationToken.None);
    if (!result) {
      return void 0;
    }
    setTimeout(() => result.dispose(), 0);
    return result.value;
  } finally {
    ref.dispose();
  }
}));
exports.Context = Context;
exports.provideSignatureHelp = provideSignatureHelp;
