parameterHints.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  9. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10. };
  11. var __param = (this && this.__param) || function (paramIndex, decorator) {
  12. return function (target, key) { decorator(target, key, paramIndex); }
  13. };
  14. import { Disposable } from '../../../base/common/lifecycle.js';
  15. import { EditorAction, EditorCommand, registerEditorAction, registerEditorCommand, registerEditorContribution } from '../../browser/editorExtensions.js';
  16. import { EditorContextKeys } from '../../common/editorContextKeys.js';
  17. import * as modes from '../../common/modes.js';
  18. import { Context } from './provideSignatureHelp.js';
  19. import * as nls from '../../../nls.js';
  20. import { ContextKeyExpr } from '../../../platform/contextkey/common/contextkey.js';
  21. import { IInstantiationService } from '../../../platform/instantiation/common/instantiation.js';
  22. import { ParameterHintsWidget } from './parameterHintsWidget.js';
  23. let ParameterHintsController = class ParameterHintsController extends Disposable {
  24. constructor(editor, instantiationService) {
  25. super();
  26. this.editor = editor;
  27. this.widget = this._register(instantiationService.createInstance(ParameterHintsWidget, this.editor));
  28. }
  29. static get(editor) {
  30. return editor.getContribution(ParameterHintsController.ID);
  31. }
  32. cancel() {
  33. this.widget.cancel();
  34. }
  35. previous() {
  36. this.widget.previous();
  37. }
  38. next() {
  39. this.widget.next();
  40. }
  41. trigger(context) {
  42. this.widget.trigger(context);
  43. }
  44. };
  45. ParameterHintsController.ID = 'editor.controller.parameterHints';
  46. ParameterHintsController = __decorate([
  47. __param(1, IInstantiationService)
  48. ], ParameterHintsController);
  49. export class TriggerParameterHintsAction extends EditorAction {
  50. constructor() {
  51. super({
  52. id: 'editor.action.triggerParameterHints',
  53. label: nls.localize('parameterHints.trigger.label', "Trigger Parameter Hints"),
  54. alias: 'Trigger Parameter Hints',
  55. precondition: EditorContextKeys.hasSignatureHelpProvider,
  56. kbOpts: {
  57. kbExpr: EditorContextKeys.editorTextFocus,
  58. primary: 2048 /* CtrlCmd */ | 1024 /* Shift */ | 10 /* Space */,
  59. weight: 100 /* EditorContrib */
  60. }
  61. });
  62. }
  63. run(accessor, editor) {
  64. const controller = ParameterHintsController.get(editor);
  65. if (controller) {
  66. controller.trigger({
  67. triggerKind: modes.SignatureHelpTriggerKind.Invoke
  68. });
  69. }
  70. }
  71. }
  72. registerEditorContribution(ParameterHintsController.ID, ParameterHintsController);
  73. registerEditorAction(TriggerParameterHintsAction);
  74. const weight = 100 /* EditorContrib */ + 75;
  75. const ParameterHintsCommand = EditorCommand.bindToContribution(ParameterHintsController.get);
  76. registerEditorCommand(new ParameterHintsCommand({
  77. id: 'closeParameterHints',
  78. precondition: Context.Visible,
  79. handler: x => x.cancel(),
  80. kbOpts: {
  81. weight: weight,
  82. kbExpr: EditorContextKeys.focus,
  83. primary: 9 /* Escape */,
  84. secondary: [1024 /* Shift */ | 9 /* Escape */]
  85. }
  86. }));
  87. registerEditorCommand(new ParameterHintsCommand({
  88. id: 'showPrevParameterHint',
  89. precondition: ContextKeyExpr.and(Context.Visible, Context.MultipleSignatures),
  90. handler: x => x.previous(),
  91. kbOpts: {
  92. weight: weight,
  93. kbExpr: EditorContextKeys.focus,
  94. primary: 16 /* UpArrow */,
  95. secondary: [512 /* Alt */ | 16 /* UpArrow */],
  96. mac: { primary: 16 /* UpArrow */, secondary: [512 /* Alt */ | 16 /* UpArrow */, 256 /* WinCtrl */ | 46 /* KeyP */] }
  97. }
  98. }));
  99. registerEditorCommand(new ParameterHintsCommand({
  100. id: 'showNextParameterHint',
  101. precondition: ContextKeyExpr.and(Context.Visible, Context.MultipleSignatures),
  102. handler: x => x.next(),
  103. kbOpts: {
  104. weight: weight,
  105. kbExpr: EditorContextKeys.focus,
  106. primary: 18 /* DownArrow */,
  107. secondary: [512 /* Alt */ | 18 /* DownArrow */],
  108. mac: { primary: 18 /* DownArrow */, secondary: [512 /* Alt */ | 18 /* DownArrow */, 256 /* WinCtrl */ | 44 /* KeyN */] }
  109. }
  110. }));