66
77import { TPromise } from 'vs/base/common/winjs.base' ;
88import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
9- import { ICommandService , ICommand , ICommandEvent , CommandsRegistry } from 'vs/platform/commands/common/commands' ;
9+ import { ICommandService , ICommandEvent , CommandsRegistry } from 'vs/platform/commands/common/commands' ;
1010import { IExtensionService } from 'vs/platform/extensions/common/extensions' ;
1111import Event , { Emitter } from 'vs/base/common/event' ;
1212import { Disposable } from 'vs/base/common/lifecycle' ;
@@ -33,17 +33,19 @@ export class CommandService extends Disposable implements ICommandService {
3333 executeCommand < T > ( id : string , ...args : any [ ] ) : TPromise < T > {
3434 // we always send an activation event, but
3535 // we don't wait for it when the extension
36- // host didn't yet start
36+ // host didn't yet start and the command is already registered
3737
3838 const activation = this . _extensionService . activateByEvent ( `onCommand:${ id } ` ) ;
3939
40- return this . _extensionHostIsReady
41- ? activation . then ( _ => this . _tryExecuteCommand ( id , args ) )
42- : this . _tryExecuteCommand ( id , args ) ;
40+ if ( ! this . _extensionHostIsReady && CommandsRegistry . getCommand ( id ) ) {
41+ return this . _tryExecuteCommand ( id , args ) ;
42+ } else {
43+ return activation . then ( _ => this . _tryExecuteCommand ( id , args ) ) ;
44+ }
4345 }
4446
4547 private _tryExecuteCommand ( id : string , args : any [ ] ) : TPromise < any > {
46- const command = this . _getCommand ( id ) ;
48+ const command = CommandsRegistry . getCommand ( id ) ;
4749 if ( ! command ) {
4850 return TPromise . wrapError ( new Error ( `command '${ id } ' not found` ) ) ;
4951 }
@@ -61,8 +63,4 @@ export class CommandService extends Disposable implements ICommandService {
6163 return TPromise . wrapError ( err ) ;
6264 }
6365 }
64-
65- private _getCommand ( id : string ) : ICommand {
66- return CommandsRegistry . getCommand ( id ) ;
67- }
6866}
0 commit comments