"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const browser = require("../../../../base/browser/browser.js");
const aria = require("../../../../base/browser/ui/aria/aria.js");
const async = require("../../../../base/common/async.js");
const keyCodes = require("../../../../base/common/keyCodes.js");
const platform = require("../../../../base/common/platform.js");
const types = require("../../../../base/common/types.js");
const uri = require("../../../../base/common/uri.js");
const editorState = require("../../editorState/browser/editorState.js");
const editorBrowser = require("../../../browser/editorBrowser.js");
const editorExtensions = require("../../../browser/editorExtensions.js");
const codeEditorService = require("../../../browser/services/codeEditorService.js");
const embeddedCodeEditorWidget = require("../../../browser/widget/embeddedCodeEditorWidget.js");
const position = require("../../../common/core/position.js");
const range = require("../../../common/core/range.js");
const editorContextKeys = require("../../../common/editorContextKeys.js");
const languages = require("../../../common/languages.js");
const referencesController = require("./peek/referencesController.js");
const referencesModel = require("./referencesModel.js");
const symbolNavigation = require("./symbolNavigation.js");
const messageController = require("../../message/browser/messageController.js");
const peekView = require("../../peekView/browser/peekView.js");
const nls = require("../../../../nls.js");
const actions = require("../../../../platform/actions/common/actions.js");
const commands = require("../../../../platform/commands/common/commands.js");
const contextkey = require("../../../../platform/contextkey/common/contextkey.js");
const instantiation = require("../../../../platform/instantiation/common/instantiation.js");
const notification = require("../../../../platform/notification/common/notification.js");
const progress = require("../../../../platform/progress/common/progress.js");
const goToSymbol = require("./goToSymbol.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());
  });
};
var _a, _b, _c, _d, _e, _f, _g, _h;
actions.MenuRegistry.appendMenuItem(actions.MenuId.EditorContext, {
  submenu: actions.MenuId.EditorContextPeek,
  title: nls.localize("peek.submenu", "Peek"),
  group: "navigation",
  order: 100
});
const _goToActionIds = /* @__PURE__ */ new Set();
function registerGoToAction(ctor) {
  const result = new ctor();
  editorExtensions.registerInstantiatedEditorAction(result);
  _goToActionIds.add(result.id);
  return result;
}
class SymbolNavigationAnchor {
  constructor(model, position2) {
    this.model = model;
    this.position = position2;
  }
  static is(thing) {
    if (!thing || typeof thing !== "object") {
      return false;
    }
    if (thing instanceof SymbolNavigationAnchor) {
      return true;
    }
    if (position.Position.isIPosition(thing.position) && thing.model) {
      return true;
    }
    return false;
  }
}
class SymbolNavigationAction extends editorExtensions.EditorAction {
  constructor(configuration, opts) {
    super(opts);
    this.configuration = configuration;
  }
  run(accessor, editor, arg) {
    if (!editor.hasModel()) {
      return Promise.resolve(void 0);
    }
    const notificationService = accessor.get(notification.INotificationService);
    const editorService = accessor.get(codeEditorService.ICodeEditorService);
    const progressService = accessor.get(progress.IEditorProgressService);
    const symbolNavService = accessor.get(symbolNavigation.ISymbolNavigationService);
    const languageFeaturesService = accessor.get(languageFeatures.ILanguageFeaturesService);
    const model = editor.getModel();
    const position2 = editor.getPosition();
    const anchor = SymbolNavigationAnchor.is(arg) ? arg : new SymbolNavigationAnchor(model, position2);
    const cts = new editorState.EditorStateCancellationTokenSource(
      editor,
      1 | 4
      /* Position */
    );
    const promise = async.raceCancellation(this._getLocationModel(languageFeaturesService, anchor.model, anchor.position, cts.token), cts.token).then((references) => __awaiter(this, void 0, void 0, function* () {
      var _a2;
      if (!references || cts.token.isCancellationRequested) {
        return;
      }
      aria.alert(references.ariaMessage);
      let altAction;
      if (references.referenceAt(model.uri, position2)) {
        const altActionId = this._getAlternativeCommand(editor);
        if (altActionId !== this.id && _goToActionIds.has(altActionId)) {
          altAction = editor.getAction(altActionId);
        }
      }
      const referenceCount = references.references.length;
      if (referenceCount === 0) {
        if (!this.configuration.muteMessage) {
          const info = model.getWordAtPosition(position2);
          (_a2 = messageController.MessageController.get(editor)) === null || _a2 === void 0 ? void 0 : _a2.showMessage(this._getNoResultFoundMessage(info), position2);
        }
      } else if (referenceCount === 1 && altAction) {
        altAction.run();
      } else {
        return this._onResult(editorService, symbolNavService, editor, references);
      }
    }), (err) => {
      notificationService.error(err);
    }).finally(() => {
      cts.dispose();
    });
    progressService.showWhile(promise, 250);
    return promise;
  }
  _onResult(editorService, symbolNavService, editor, model) {
    return __awaiter(this, void 0, void 0, function* () {
      const gotoLocation = this._getGoToPreference(editor);
      if (!(editor instanceof embeddedCodeEditorWidget.EmbeddedCodeEditorWidget) && (this.configuration.openInPeek || gotoLocation === "peek" && model.references.length > 1)) {
        this._openInPeek(editor, model);
      } else {
        const next = model.firstReference();
        const peek = model.references.length > 1 && gotoLocation === "gotoAndPeek";
        const targetEditor = yield this._openReference(editor, editorService, next, this.configuration.openToSide, !peek);
        if (peek && targetEditor) {
          this._openInPeek(targetEditor, model);
        } else {
          model.dispose();
        }
        if (gotoLocation === "goto") {
          symbolNavService.put(next);
        }
      }
    });
  }
  _openReference(editor, editorService, reference, sideBySide, highlight) {
    return __awaiter(this, void 0, void 0, function* () {
      let range$1 = void 0;
      if (languages.isLocationLink(reference)) {
        range$1 = reference.targetSelectionRange;
      }
      if (!range$1) {
        range$1 = reference.range;
      }
      if (!range$1) {
        return void 0;
      }
      const targetEditor = yield editorService.openCodeEditor({
        resource: reference.uri,
        options: {
          selection: range.Range.collapseToStart(range$1),
          selectionRevealType: 3,
          selectionSource: "code.jump"
          /* JUMP */
        }
      }, editor, sideBySide);
      if (!targetEditor) {
        return void 0;
      }
      if (highlight) {
        const modelNow = targetEditor.getModel();
        const ids = targetEditor.deltaDecorations([], [{ range: range$1, options: { description: "symbol-navigate-action-highlight", className: "symbolHighlight" } }]);
        setTimeout(() => {
          if (targetEditor.getModel() === modelNow) {
            targetEditor.deltaDecorations(ids, []);
          }
        }, 350);
      }
      return targetEditor;
    });
  }
  _openInPeek(target, model) {
    const controller = referencesController.ReferencesController.get(target);
    if (controller && target.hasModel()) {
      controller.toggleWidget(target.getSelection(), async.createCancelablePromise((_) => Promise.resolve(model)), this.configuration.openInPeek);
    } else {
      model.dispose();
    }
  }
}
class DefinitionAction extends SymbolNavigationAction {
  _getLocationModel(languageFeaturesService, model, position2, token) {
    return __awaiter(this, void 0, void 0, function* () {
      return new referencesModel.ReferencesModel(yield goToSymbol.getDefinitionsAtPosition(languageFeaturesService.definitionProvider, model, position2, token), nls.localize("def.title", "Definitions"));
    });
  }
  _getNoResultFoundMessage(info) {
    return info && info.word ? nls.localize("noResultWord", "No definition found for '{0}'", info.word) : nls.localize("generic.noResults", "No definition found");
  }
  _getAlternativeCommand(editor) {
    return editor.getOption(
      51
      /* gotoLocation */
    ).alternativeDefinitionCommand;
  }
  _getGoToPreference(editor) {
    return editor.getOption(
      51
      /* gotoLocation */
    ).multipleDefinitions;
  }
}
const goToDefinitionKb = platform.isWeb && !browser.isStandalone ? 2048 | 70 : 70;
registerGoToAction((_a = class GoToDefinitionAction extends DefinitionAction {
  constructor() {
    super({
      openToSide: false,
      openInPeek: false,
      muteMessage: false
    }, {
      id: GoToDefinitionAction.id,
      label: nls.localize("actions.goToDecl.label", "Go to Definition"),
      alias: "Go to Definition",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasDefinitionProvider, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      kbOpts: {
        kbExpr: editorContextKeys.EditorContextKeys.editorTextFocus,
        primary: goToDefinitionKb,
        weight: 100
        /* EditorContrib */
      },
      contextMenuOpts: {
        group: "navigation",
        order: 1.1
      }
    });
    commands.CommandsRegistry.registerCommandAlias("editor.action.goToDeclaration", GoToDefinitionAction.id);
  }
}, _a.id = "editor.action.revealDefinition", _a));
registerGoToAction((_b = class OpenDefinitionToSideAction extends DefinitionAction {
  constructor() {
    super({
      openToSide: true,
      openInPeek: false,
      muteMessage: false
    }, {
      id: OpenDefinitionToSideAction.id,
      label: nls.localize("actions.goToDeclToSide.label", "Open Definition to the Side"),
      alias: "Open Definition to the Side",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasDefinitionProvider, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      kbOpts: {
        kbExpr: editorContextKeys.EditorContextKeys.editorTextFocus,
        primary: keyCodes.KeyChord(2048 | 41, goToDefinitionKb),
        weight: 100
        /* EditorContrib */
      }
    });
    commands.CommandsRegistry.registerCommandAlias("editor.action.openDeclarationToTheSide", OpenDefinitionToSideAction.id);
  }
}, _b.id = "editor.action.revealDefinitionAside", _b));
registerGoToAction((_c = class PeekDefinitionAction extends DefinitionAction {
  constructor() {
    super({
      openToSide: false,
      openInPeek: true,
      muteMessage: false
    }, {
      id: PeekDefinitionAction.id,
      label: nls.localize("actions.previewDecl.label", "Peek Definition"),
      alias: "Peek Definition",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasDefinitionProvider, peekView.PeekContext.notInPeekEditor, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      kbOpts: {
        kbExpr: editorContextKeys.EditorContextKeys.editorTextFocus,
        primary: 512 | 70,
        linux: {
          primary: 2048 | 1024 | 68
          /* F10 */
        },
        weight: 100
        /* EditorContrib */
      },
      contextMenuOpts: {
        menuId: actions.MenuId.EditorContextPeek,
        group: "peek",
        order: 2
      }
    });
    commands.CommandsRegistry.registerCommandAlias("editor.action.previewDeclaration", PeekDefinitionAction.id);
  }
}, _c.id = "editor.action.peekDefinition", _c));
class DeclarationAction extends SymbolNavigationAction {
  _getLocationModel(languageFeaturesService, model, position2, token) {
    return __awaiter(this, void 0, void 0, function* () {
      return new referencesModel.ReferencesModel(yield goToSymbol.getDeclarationsAtPosition(languageFeaturesService.declarationProvider, model, position2, token), nls.localize("decl.title", "Declarations"));
    });
  }
  _getNoResultFoundMessage(info) {
    return info && info.word ? nls.localize("decl.noResultWord", "No declaration found for '{0}'", info.word) : nls.localize("decl.generic.noResults", "No declaration found");
  }
  _getAlternativeCommand(editor) {
    return editor.getOption(
      51
      /* gotoLocation */
    ).alternativeDeclarationCommand;
  }
  _getGoToPreference(editor) {
    return editor.getOption(
      51
      /* gotoLocation */
    ).multipleDeclarations;
  }
}
registerGoToAction((_d = class GoToDeclarationAction extends DeclarationAction {
  constructor() {
    super({
      openToSide: false,
      openInPeek: false,
      muteMessage: false
    }, {
      id: GoToDeclarationAction.id,
      label: nls.localize("actions.goToDeclaration.label", "Go to Declaration"),
      alias: "Go to Declaration",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasDeclarationProvider, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      contextMenuOpts: {
        group: "navigation",
        order: 1.3
      }
    });
  }
  _getNoResultFoundMessage(info) {
    return info && info.word ? nls.localize("decl.noResultWord", "No declaration found for '{0}'", info.word) : nls.localize("decl.generic.noResults", "No declaration found");
  }
}, _d.id = "editor.action.revealDeclaration", _d));
registerGoToAction(class PeekDeclarationAction extends DeclarationAction {
  constructor() {
    super({
      openToSide: false,
      openInPeek: true,
      muteMessage: false
    }, {
      id: "editor.action.peekDeclaration",
      label: nls.localize("actions.peekDecl.label", "Peek Declaration"),
      alias: "Peek Declaration",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasDeclarationProvider, peekView.PeekContext.notInPeekEditor, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      contextMenuOpts: {
        menuId: actions.MenuId.EditorContextPeek,
        group: "peek",
        order: 3
      }
    });
  }
});
class TypeDefinitionAction extends SymbolNavigationAction {
  _getLocationModel(languageFeaturesService, model, position2, token) {
    return __awaiter(this, void 0, void 0, function* () {
      return new referencesModel.ReferencesModel(yield goToSymbol.getTypeDefinitionsAtPosition(languageFeaturesService.typeDefinitionProvider, model, position2, token), nls.localize("typedef.title", "Type Definitions"));
    });
  }
  _getNoResultFoundMessage(info) {
    return info && info.word ? nls.localize("goToTypeDefinition.noResultWord", "No type definition found for '{0}'", info.word) : nls.localize("goToTypeDefinition.generic.noResults", "No type definition found");
  }
  _getAlternativeCommand(editor) {
    return editor.getOption(
      51
      /* gotoLocation */
    ).alternativeTypeDefinitionCommand;
  }
  _getGoToPreference(editor) {
    return editor.getOption(
      51
      /* gotoLocation */
    ).multipleTypeDefinitions;
  }
}
registerGoToAction((_e = class GoToTypeDefinitionAction extends TypeDefinitionAction {
  constructor() {
    super({
      openToSide: false,
      openInPeek: false,
      muteMessage: false
    }, {
      id: GoToTypeDefinitionAction.ID,
      label: nls.localize("actions.goToTypeDefinition.label", "Go to Type Definition"),
      alias: "Go to Type Definition",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasTypeDefinitionProvider, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      kbOpts: {
        kbExpr: editorContextKeys.EditorContextKeys.editorTextFocus,
        primary: 0,
        weight: 100
        /* EditorContrib */
      },
      contextMenuOpts: {
        group: "navigation",
        order: 1.4
      }
    });
  }
}, _e.ID = "editor.action.goToTypeDefinition", _e));
registerGoToAction((_f = class PeekTypeDefinitionAction extends TypeDefinitionAction {
  constructor() {
    super({
      openToSide: false,
      openInPeek: true,
      muteMessage: false
    }, {
      id: PeekTypeDefinitionAction.ID,
      label: nls.localize("actions.peekTypeDefinition.label", "Peek Type Definition"),
      alias: "Peek Type Definition",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasTypeDefinitionProvider, peekView.PeekContext.notInPeekEditor, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      contextMenuOpts: {
        menuId: actions.MenuId.EditorContextPeek,
        group: "peek",
        order: 4
      }
    });
  }
}, _f.ID = "editor.action.peekTypeDefinition", _f));
class ImplementationAction extends SymbolNavigationAction {
  _getLocationModel(languageFeaturesService, model, position2, token) {
    return __awaiter(this, void 0, void 0, function* () {
      return new referencesModel.ReferencesModel(yield goToSymbol.getImplementationsAtPosition(languageFeaturesService.implementationProvider, model, position2, token), nls.localize("impl.title", "Implementations"));
    });
  }
  _getNoResultFoundMessage(info) {
    return info && info.word ? nls.localize("goToImplementation.noResultWord", "No implementation found for '{0}'", info.word) : nls.localize("goToImplementation.generic.noResults", "No implementation found");
  }
  _getAlternativeCommand(editor) {
    return editor.getOption(
      51
      /* gotoLocation */
    ).alternativeImplementationCommand;
  }
  _getGoToPreference(editor) {
    return editor.getOption(
      51
      /* gotoLocation */
    ).multipleImplementations;
  }
}
registerGoToAction((_g = class GoToImplementationAction extends ImplementationAction {
  constructor() {
    super({
      openToSide: false,
      openInPeek: false,
      muteMessage: false
    }, {
      id: GoToImplementationAction.ID,
      label: nls.localize("actions.goToImplementation.label", "Go to Implementations"),
      alias: "Go to Implementations",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasImplementationProvider, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      kbOpts: {
        kbExpr: editorContextKeys.EditorContextKeys.editorTextFocus,
        primary: 2048 | 70,
        weight: 100
        /* EditorContrib */
      },
      contextMenuOpts: {
        group: "navigation",
        order: 1.45
      }
    });
  }
}, _g.ID = "editor.action.goToImplementation", _g));
registerGoToAction((_h = class PeekImplementationAction extends ImplementationAction {
  constructor() {
    super({
      openToSide: false,
      openInPeek: true,
      muteMessage: false
    }, {
      id: PeekImplementationAction.ID,
      label: nls.localize("actions.peekImplementation.label", "Peek Implementations"),
      alias: "Peek Implementations",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasImplementationProvider, peekView.PeekContext.notInPeekEditor, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      kbOpts: {
        kbExpr: editorContextKeys.EditorContextKeys.editorTextFocus,
        primary: 2048 | 1024 | 70,
        weight: 100
        /* EditorContrib */
      },
      contextMenuOpts: {
        menuId: actions.MenuId.EditorContextPeek,
        group: "peek",
        order: 5
      }
    });
  }
}, _h.ID = "editor.action.peekImplementation", _h));
class ReferencesAction extends SymbolNavigationAction {
  _getNoResultFoundMessage(info) {
    return info ? nls.localize("references.no", "No references found for '{0}'", info.word) : nls.localize("references.noGeneric", "No references found");
  }
  _getAlternativeCommand(editor) {
    return editor.getOption(
      51
      /* gotoLocation */
    ).alternativeReferenceCommand;
  }
  _getGoToPreference(editor) {
    return editor.getOption(
      51
      /* gotoLocation */
    ).multipleReferences;
  }
}
registerGoToAction(class GoToReferencesAction extends ReferencesAction {
  constructor() {
    super({
      openToSide: false,
      openInPeek: false,
      muteMessage: false
    }, {
      id: "editor.action.goToReferences",
      label: nls.localize("goToReferences.label", "Go to References"),
      alias: "Go to References",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasReferenceProvider, peekView.PeekContext.notInPeekEditor, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      kbOpts: {
        kbExpr: editorContextKeys.EditorContextKeys.editorTextFocus,
        primary: 1024 | 70,
        weight: 100
        /* EditorContrib */
      },
      contextMenuOpts: {
        group: "navigation",
        order: 1.45
      }
    });
  }
  _getLocationModel(languageFeaturesService, model, position2, token) {
    return __awaiter(this, void 0, void 0, function* () {
      return new referencesModel.ReferencesModel(yield goToSymbol.getReferencesAtPosition(languageFeaturesService.referenceProvider, model, position2, true, token), nls.localize("ref.title", "References"));
    });
  }
});
registerGoToAction(class PeekReferencesAction extends ReferencesAction {
  constructor() {
    super({
      openToSide: false,
      openInPeek: true,
      muteMessage: false
    }, {
      id: "editor.action.referenceSearch.trigger",
      label: nls.localize("references.action.label", "Peek References"),
      alias: "Peek References",
      precondition: contextkey.ContextKeyExpr.and(editorContextKeys.EditorContextKeys.hasReferenceProvider, peekView.PeekContext.notInPeekEditor, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated()),
      contextMenuOpts: {
        menuId: actions.MenuId.EditorContextPeek,
        group: "peek",
        order: 6
      }
    });
  }
  _getLocationModel(languageFeaturesService, model, position2, token) {
    return __awaiter(this, void 0, void 0, function* () {
      return new referencesModel.ReferencesModel(yield goToSymbol.getReferencesAtPosition(languageFeaturesService.referenceProvider, model, position2, false, token), nls.localize("ref.title", "References"));
    });
  }
});
class GenericGoToLocationAction extends SymbolNavigationAction {
  constructor(config, _references, _gotoMultipleBehaviour) {
    super(config, {
      id: "editor.action.goToLocation",
      label: nls.localize("label.generic", "Go to Any Symbol"),
      alias: "Go to Any Symbol",
      precondition: contextkey.ContextKeyExpr.and(peekView.PeekContext.notInPeekEditor, editorContextKeys.EditorContextKeys.isInWalkThroughSnippet.toNegated())
    });
    this._references = _references;
    this._gotoMultipleBehaviour = _gotoMultipleBehaviour;
  }
  _getLocationModel(languageFeaturesService, _model, _position, _token) {
    return __awaiter(this, void 0, void 0, function* () {
      return new referencesModel.ReferencesModel(this._references, nls.localize("generic.title", "Locations"));
    });
  }
  _getNoResultFoundMessage(info) {
    return info && nls.localize("generic.noResult", "No results for '{0}'", info.word) || "";
  }
  _getGoToPreference(editor) {
    var _a2;
    return (_a2 = this._gotoMultipleBehaviour) !== null && _a2 !== void 0 ? _a2 : editor.getOption(
      51
      /* gotoLocation */
    ).multipleReferences;
  }
  _getAlternativeCommand() {
    return "";
  }
}
commands.CommandsRegistry.registerCommand({
  id: "editor.action.goToLocations",
  description: {
    description: "Go to locations from a position in a file",
    args: [
      { name: "uri", description: "The text document in which to start", constraint: uri.URI },
      { name: "position", description: "The position at which to start", constraint: position.Position.isIPosition },
      { name: "locations", description: "An array of locations.", constraint: Array },
      { name: "multiple", description: "Define what to do when having multiple results, either `peek`, `gotoAndPeek`, or `goto" },
      { name: "noResultsMessage", description: "Human readable message that shows when locations is empty." }
    ]
  },
  handler: (accessor, resource, position$1, references, multiple, noResultsMessage, openInPeek) => __awaiter(void 0, void 0, void 0, function* () {
    types.assertType(uri.URI.isUri(resource));
    types.assertType(position.Position.isIPosition(position$1));
    types.assertType(Array.isArray(references));
    types.assertType(typeof multiple === "undefined" || typeof multiple === "string");
    types.assertType(typeof openInPeek === "undefined" || typeof openInPeek === "boolean");
    const editorService = accessor.get(codeEditorService.ICodeEditorService);
    const editor = yield editorService.openCodeEditor({ resource }, editorService.getFocusedCodeEditor());
    if (editorBrowser.isCodeEditor(editor)) {
      editor.setPosition(position$1);
      editor.revealPositionInCenterIfOutsideViewport(
        position$1,
        0
        /* Smooth */
      );
      return editor.invokeWithinContext((accessor2) => {
        const command = new class extends GenericGoToLocationAction {
          _getNoResultFoundMessage(info) {
            return noResultsMessage || super._getNoResultFoundMessage(info);
          }
        }({
          muteMessage: !Boolean(noResultsMessage),
          openInPeek: Boolean(openInPeek),
          openToSide: false
        }, references, multiple);
        accessor2.get(instantiation.IInstantiationService).invokeFunction(command.run.bind(command), editor);
      });
    }
  })
});
commands.CommandsRegistry.registerCommand({
  id: "editor.action.peekLocations",
  description: {
    description: "Peek locations from a position in a file",
    args: [
      { name: "uri", description: "The text document in which to start", constraint: uri.URI },
      { name: "position", description: "The position at which to start", constraint: position.Position.isIPosition },
      { name: "locations", description: "An array of locations.", constraint: Array },
      { name: "multiple", description: "Define what to do when having multiple results, either `peek`, `gotoAndPeek`, or `goto" }
    ]
  },
  handler: (accessor, resource, position2, references, multiple) => __awaiter(void 0, void 0, void 0, function* () {
    accessor.get(commands.ICommandService).executeCommand("editor.action.goToLocations", resource, position2, references, multiple, void 0, true);
  })
});
commands.CommandsRegistry.registerCommand({
  id: "editor.action.findReferences",
  handler: (accessor, resource, position$1) => {
    types.assertType(uri.URI.isUri(resource));
    types.assertType(position.Position.isIPosition(position$1));
    const languageFeaturesService = accessor.get(languageFeatures.ILanguageFeaturesService);
    const codeEditorService$1 = accessor.get(codeEditorService.ICodeEditorService);
    return codeEditorService$1.openCodeEditor({ resource }, codeEditorService$1.getFocusedCodeEditor()).then((control) => {
      if (!editorBrowser.isCodeEditor(control) || !control.hasModel()) {
        return void 0;
      }
      const controller = referencesController.ReferencesController.get(control);
      if (!controller) {
        return void 0;
      }
      const references = async.createCancelablePromise((token) => goToSymbol.getReferencesAtPosition(languageFeaturesService.referenceProvider, control.getModel(), position.Position.lift(position$1), false, token).then((references2) => new referencesModel.ReferencesModel(references2, nls.localize("ref.title", "References"))));
      const range$1 = new range.Range(position$1.lineNumber, position$1.column, position$1.lineNumber, position$1.column);
      return Promise.resolve(controller.toggleWidget(range$1, references, false));
    });
  }
});
commands.CommandsRegistry.registerCommandAlias("editor.action.showReferences", "editor.action.peekLocations");
actions.MenuRegistry.appendMenuItems([
  {
    id: actions.MenuId.MenubarGoMenu,
    item: {
      command: {
        id: "editor.action.revealDefinition",
        title: nls.localize({ key: "miGotoDefinition", comment: ["&& denotes a mnemonic"] }, "Go to &&Definition")
      },
      group: "4_symbol_nav",
      order: 2
    }
  },
  {
    id: actions.MenuId.MenubarGoMenu,
    item: {
      command: {
        id: "editor.action.revealDeclaration",
        title: nls.localize({ key: "miGotoDeclaration", comment: ["&& denotes a mnemonic"] }, "Go to &&Declaration")
      },
      group: "4_symbol_nav",
      order: 3
    }
  },
  {
    id: actions.MenuId.MenubarGoMenu,
    item: {
      command: {
        id: "editor.action.goToTypeDefinition",
        title: nls.localize({ key: "miGotoTypeDefinition", comment: ["&& denotes a mnemonic"] }, "Go to &&Type Definition")
      },
      group: "4_symbol_nav",
      order: 3
    }
  },
  {
    id: actions.MenuId.MenubarGoMenu,
    item: {
      command: {
        id: "editor.action.goToImplementation",
        title: nls.localize({ key: "miGotoImplementation", comment: ["&& denotes a mnemonic"] }, "Go to &&Implementations")
      },
      group: "4_symbol_nav",
      order: 4
    }
  },
  {
    id: actions.MenuId.MenubarGoMenu,
    item: {
      command: {
        id: "editor.action.goToReferences",
        title: nls.localize({ key: "miGotoReference", comment: ["&& denotes a mnemonic"] }, "Go to &&References")
      },
      group: "4_symbol_nav",
      order: 5
    }
  }
]);
exports.DefinitionAction = DefinitionAction;
exports.SymbolNavigationAction = SymbolNavigationAction;
exports.SymbolNavigationAnchor = SymbolNavigationAnchor;
