023a1b45ef70a6eea3dff33e5ac3853b2e33165b8fa129f799e81b1a3a44b08aa23f9bb81b2d7405ec24efbefc0814f0541032869a15d515988dbb3d823a7b 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. import { EditorCommand, registerEditorAction, registerEditorCommand, registerEditorContribution } from '../../../browser/editorExtensions.js';
  6. import { EditorContextKeys } from '../../../common/editorContextKeys.js';
  7. import { HoverParticipantRegistry } from '../../hover/browser/hoverTypes.js';
  8. import { inlineSuggestCommitId } from './consts.js';
  9. import { GhostTextController, ShowNextInlineSuggestionAction, ShowPreviousInlineSuggestionAction, TriggerInlineSuggestionAction } from './ghostTextController.js';
  10. import { InlineCompletionsHoverParticipant } from './ghostTextHoverParticipant.js';
  11. import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
  12. import { KeybindingsRegistry } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
  13. registerEditorContribution(GhostTextController.ID, GhostTextController);
  14. registerEditorAction(TriggerInlineSuggestionAction);
  15. registerEditorAction(ShowNextInlineSuggestionAction);
  16. registerEditorAction(ShowPreviousInlineSuggestionAction);
  17. HoverParticipantRegistry.register(InlineCompletionsHoverParticipant);
  18. const GhostTextCommand = EditorCommand.bindToContribution(GhostTextController.get);
  19. export const commitInlineSuggestionAction = new GhostTextCommand({
  20. id: inlineSuggestCommitId,
  21. precondition: GhostTextController.inlineSuggestionVisible,
  22. handler(x) {
  23. x.commit();
  24. x.editor.focus();
  25. }
  26. });
  27. registerEditorCommand(commitInlineSuggestionAction);
  28. KeybindingsRegistry.registerKeybindingRule({
  29. primary: 2 /* KeyCode.Tab */,
  30. weight: 200,
  31. id: commitInlineSuggestionAction.id,
  32. when: ContextKeyExpr.and(commitInlineSuggestionAction.precondition, EditorContextKeys.tabMovesFocus.toNegated(), GhostTextController.inlineSuggestionHasIndentationLessThanTabSize),
  33. });
  34. registerEditorCommand(new GhostTextCommand({
  35. id: 'editor.action.inlineSuggest.hide',
  36. precondition: GhostTextController.inlineSuggestionVisible,
  37. kbOpts: {
  38. weight: 100,
  39. primary: 9 /* KeyCode.Escape */,
  40. },
  41. handler(x) {
  42. x.hide();
  43. }
  44. }));