44 *--------------------------------------------------------------------------------------------*/
55
66import { validateConstraint } from 'vs/base/common/types' ;
7- import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands' ;
7+ import { ICommandHandlerDescription , ICommandEvent } from 'vs/platform/commands/common/commands' ;
88import * as extHostTypes from 'vs/workbench/api/common/extHostTypes' ;
99import * as extHostTypeConverter from 'vs/workbench/api/common/extHostTypeConverters' ;
1010import { cloneAndChange } from 'vs/base/common/objects' ;
@@ -17,6 +17,7 @@ import { revive } from 'vs/base/common/marshalling';
1717import { Range } from 'vs/editor/common/core/range' ;
1818import { Position } from 'vs/editor/common/core/position' ;
1919import { URI } from 'vs/base/common/uri' ;
20+ import { Event , Emitter } from 'vs/base/common/event' ;
2021import { DisposableStore , toDisposable } from 'vs/base/common/lifecycle' ;
2122
2223interface CommandHandler {
@@ -31,6 +32,9 @@ export interface ArgumentProcessor {
3132
3233export class ExtHostCommands implements ExtHostCommandsShape {
3334
35+ private readonly _onDidExecuteCommand : Emitter < vscode . CommandExecutionEvent > ;
36+ readonly onDidExecuteCommand : Event < vscode . CommandExecutionEvent > ;
37+
3438 private readonly _commands = new Map < string , CommandHandler > ( ) ;
3539 private readonly _proxy : MainThreadCommandsShape ;
3640 private readonly _converter : CommandsConverter ;
@@ -42,6 +46,11 @@ export class ExtHostCommands implements ExtHostCommandsShape {
4246 logService : ILogService
4347 ) {
4448 this . _proxy = mainContext . getProxy ( MainContext . MainThreadCommands ) ;
49+ this . _onDidExecuteCommand = new Emitter < vscode . CommandExecutionEvent > ( {
50+ onFirstListenerDidAdd : ( ) => this . _proxy . $registerCommandListener ( ) ,
51+ onLastListenerRemove : ( ) => this . _proxy . $unregisterCommandListener ( ) ,
52+ } ) ;
53+ this . onDidExecuteCommand = this . _onDidExecuteCommand . event ;
4554 this . _logService = logService ;
4655 this . _converter = new CommandsConverter ( this ) ;
4756 this . _argumentProcessors = [
@@ -106,6 +115,10 @@ export class ExtHostCommands implements ExtHostCommandsShape {
106115 } ) ;
107116 }
108117
118+ $handleDidExecuteCommand ( command : ICommandEvent ) : void {
119+ this . _onDidExecuteCommand . fire ( { command : command . commandId , arguments : command . args } ) ;
120+ }
121+
109122 executeCommand < T > ( id : string , ...args : any [ ] ) : Promise < T > {
110123 this . _logService . trace ( 'ExtHostCommands#executeCommand' , id ) ;
111124
@@ -154,6 +167,7 @@ export class ExtHostCommands implements ExtHostCommandsShape {
154167
155168 try {
156169 const result = callback . apply ( thisArg , args ) ;
170+ this . _onDidExecuteCommand . fire ( { command : id , arguments : args } ) ;
157171 return Promise . resolve ( result ) ;
158172 } catch ( err ) {
159173 this . _logService . error ( err , id ) ;
0 commit comments