@@ -8,7 +8,7 @@ import { SyncDescriptor0, createSyncDescriptor } from 'vs/platform/instantiation
88import { IConstructorSignature2 , createDecorator , BrandedService , ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
99import { IKeybindings , KeybindingsRegistry , IKeybindingRule } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
1010import { ContextKeyExpr , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
11- import { ICommandService , CommandsRegistry } from 'vs/platform/commands/common/commands' ;
11+ import { ICommandService , CommandsRegistry , ICommandHandlerDescription } from 'vs/platform/commands/common/commands' ;
1212import { IDisposable , DisposableStore } from 'vs/base/common/lifecycle' ;
1313import { Event , Emitter } from 'vs/base/common/event' ;
1414import { URI , UriComponents } from 'vs/base/common/uri' ;
@@ -351,9 +351,27 @@ export class SyncActionDescriptor {
351351type OneOrN < T > = T | T [ ] ;
352352
353353export interface IAction2Options extends ICommandAction {
354+
355+ /**
356+ * Shorthand to add this command to the command palette
357+ */
354358 f1 ?: boolean ;
359+
360+ /**
361+ * One or many menu items.
362+ */
355363 menu ?: OneOrN < { id : MenuId } & Omit < IMenuItem , 'command' > > ;
356- keybinding ?: Omit < IKeybindingRule , 'id' > ;
364+
365+ /**
366+ * One keybinding.
367+ */
368+ keybinding ?: OneOrN < Omit < IKeybindingRule , 'id' > > ;
369+
370+ /**
371+ * Metadata about this command, used for API commands or when
372+ * showing keybindings that have no other UX.
373+ */
374+ description ?: ICommandHandlerDescription ;
357375}
358376
359377export abstract class Action2 {
@@ -364,25 +382,36 @@ export abstract class Action2 {
364382export function registerAction2 ( ctor : { new ( ) : Action2 } ) : IDisposable {
365383 const disposables = new DisposableStore ( ) ;
366384 const action = new ctor ( ) ;
385+
386+ // command
367387 disposables . add ( CommandsRegistry . registerCommand ( {
368388 id : action . desc . id ,
369389 handler : ( accessor , ...args ) => action . run ( accessor , ...args ) ,
370- description : undefined ,
390+ description : action . desc . description ,
371391 } ) ) ;
372392
393+ // menu
373394 if ( Array . isArray ( action . desc . menu ) ) {
374395 for ( let item of action . desc . menu ) {
375396 disposables . add ( MenuRegistry . appendMenuItem ( item . id , { command : action . desc , ...item } ) ) ;
376397 }
377398 } else if ( action . desc . menu ) {
378399 disposables . add ( MenuRegistry . appendMenuItem ( action . desc . menu . id , { command : action . desc , ...action . desc . menu } ) ) ;
379400 }
380-
381401 if ( action . desc . f1 ) {
382402 disposables . add ( MenuRegistry . appendMenuItem ( MenuId . CommandPalette , { command : action . desc , ...action . desc } ) ) ;
383403 }
384404
385- if ( action . desc . keybinding ) {
405+ // keybinding
406+ if ( Array . isArray ( action . desc . keybinding ) ) {
407+ for ( let item of action . desc . keybinding ) {
408+ KeybindingsRegistry . registerKeybindingRule ( {
409+ ...item ,
410+ id : action . desc . id ,
411+ when : ContextKeyExpr . and ( action . desc . precondition , item . when )
412+ } ) ;
413+ }
414+ } else if ( action . desc . keybinding ) {
386415 KeybindingsRegistry . registerKeybindingRule ( {
387416 ...action . desc . keybinding ,
388417 id : action . desc . id ,
0 commit comments