11import { Autowired } from '@opensumi/di' ;
22import {
3+ AINativeConfigService ,
34 ClientAppContribution ,
45 Key ,
56 KeybindingContribution ,
67 KeybindingRegistry ,
78 KeybindingScope ,
89} from '@opensumi/ide-core-browser' ;
9- import {
10- AI_MULTI_LINE_COMPLETION_ACCEPT ,
11- AI_MULTI_LINE_COMPLETION_DISCARD ,
12- } from '@opensumi/ide-core-browser/lib/ai-native/command' ;
10+ import { AI_CODE_EDITS_COMMANDS } from '@opensumi/ide-core-browser/lib/ai-native/command' ;
1311import { MultiLineEditsIsVisible } from '@opensumi/ide-core-browser/lib/contextkey/ai-native' ;
1412import { CommandContribution , CommandRegistry , Domain } from '@opensumi/ide-core-common' ;
1513import { WorkbenchEditorService } from '@opensumi/ide-editor' ;
1614import { WorkbenchEditorServiceImpl } from '@opensumi/ide-editor/lib/browser/workbench-editor.service' ;
15+ import { transaction } from '@opensumi/ide-monaco/lib/common/observable' ;
1716
1817import { IntelligentCompletionsController } from './intelligent-completions.controller' ;
1918
@@ -22,8 +21,11 @@ export class IntelligentCompletionsContribution implements KeybindingContributio
2221 @Autowired ( WorkbenchEditorService )
2322 private readonly workbenchEditorService : WorkbenchEditorServiceImpl ;
2423
24+ @Autowired ( AINativeConfigService )
25+ private readonly aiNativeConfigService : AINativeConfigService ;
26+
2527 registerCommands ( commands : CommandRegistry ) : void {
26- commands . registerCommand ( AI_MULTI_LINE_COMPLETION_DISCARD , {
28+ commands . registerCommand ( AI_CODE_EDITS_COMMANDS . DISCARD , {
2729 execute : ( ) => {
2830 const editor = this . workbenchEditorService . currentCodeEditor ;
2931 if ( editor ) {
@@ -32,31 +34,50 @@ export class IntelligentCompletionsContribution implements KeybindingContributio
3234 } ,
3335 } ) ;
3436
35- commands . registerCommand ( AI_MULTI_LINE_COMPLETION_ACCEPT , {
37+ commands . registerCommand ( AI_CODE_EDITS_COMMANDS . ACCEPT , {
3638 execute : ( ) => {
3739 const editor = this . workbenchEditorService . currentCodeEditor ;
3840 if ( editor ) {
3941 IntelligentCompletionsController . get ( editor . monacoEditor ) ?. accept . get ( ) ;
4042 }
4143 } ,
4244 } ) ;
45+
46+ commands . registerCommand ( AI_CODE_EDITS_COMMANDS . TRIGGER , {
47+ execute : ( ) => {
48+ const editor = this . workbenchEditorService . currentCodeEditor ;
49+ if ( editor ) {
50+ transaction ( ( tx ) => {
51+ IntelligentCompletionsController . get ( editor . monacoEditor ) ?. trigger ( tx ) ;
52+ } ) ;
53+ }
54+ } ,
55+ } ) ;
4356 }
4457
4558 registerKeybindings ( keybindings : KeybindingRegistry ) : void {
59+ const { codeEdits } = this . aiNativeConfigService ;
60+
4661 keybindings . registerKeybinding ( {
47- command : AI_MULTI_LINE_COMPLETION_DISCARD . id ,
62+ command : AI_CODE_EDITS_COMMANDS . DISCARD . id ,
4863 keybinding : Key . ESCAPE . code ,
4964 when : MultiLineEditsIsVisible . raw ,
5065 priority : 100 ,
5166 } ) ;
5267
5368 keybindings . registerKeybinding (
5469 {
55- command : AI_MULTI_LINE_COMPLETION_ACCEPT . id ,
70+ command : AI_CODE_EDITS_COMMANDS . ACCEPT . id ,
5671 keybinding : Key . TAB . code ,
5772 when : MultiLineEditsIsVisible . raw ,
5873 } ,
5974 KeybindingScope . USER ,
6075 ) ;
76+
77+ keybindings . registerKeybinding ( {
78+ command : AI_CODE_EDITS_COMMANDS . TRIGGER . id ,
79+ keybinding : codeEdits . triggerKeybinding ,
80+ when : 'editorFocus' ,
81+ } ) ;
6182 }
6283}
0 commit comments