From fa406d2dd15cc9bc1fc11cc11843e20180e1c4ed Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 16 May 2019 09:51:30 -0700 Subject: [PATCH] tiny tweaks --- src/vs/vscode.proposed.d.ts | 16 +++++++++++----- .../api/browser/mainThreadCommands.ts | 17 +++++++++-------- src/vs/workbench/api/common/extHostCommands.ts | 18 +++++++----------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 370c8524198..bd90b412ab1 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -555,16 +555,22 @@ declare module 'vscode' { * @return Disposable which unregisters this command on disposal. */ export function registerDiffInformationCommand(command: string, callback: (diff: LineChange[], ...args: any[]) => any, thisArg?: any): Disposable; + } + + //#endregion - export interface ICommandEvent { - commandId: string; - args: any[]; - } + //#region Joh: onDidExecuteCommand + export interface CommandExecutionEvent { + command: string; + arguments: any[]; + } + + export namespace commands { /** * An event that is emitted when a [command](#Command) is executed. */ - export const onDidExecuteCommand: Event; + export const onDidExecuteCommand: Event; } //#endregion diff --git a/src/vs/workbench/api/browser/mainThreadCommands.ts b/src/vs/workbench/api/browser/mainThreadCommands.ts index 1f63ed47dd0..aab239bebd5 100644 --- a/src/vs/workbench/api/browser/mainThreadCommands.ts +++ b/src/vs/workbench/api/browser/mainThreadCommands.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { ICommandService, CommandsRegistry, ICommandHandlerDescription, ICommandEvent } from 'vs/platform/commands/common/commands'; +import { ICommandService, CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands'; import { IDisposable } from 'vs/base/common/lifecycle'; import { ExtHostContext, MainThreadCommandsShape, ExtHostCommandsShape, MainContext, IExtHostContext } from '../common/extHost.protocol'; import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; @@ -15,7 +15,7 @@ export class MainThreadCommands implements MainThreadCommandsShape { private readonly _disposables = new Map(); private readonly _generateCommandsDocumentationRegistration: IDisposable; private readonly _proxy: ExtHostCommandsShape; - private _onDidExecuteCommandListener: IDisposable; + private _onDidExecuteCommandListener?: IDisposable; constructor( extHostContext: IExtHostContext, @@ -80,20 +80,21 @@ export class MainThreadCommands implements MainThreadCommandsShape { } $registerCommandListener() { - this._onDidExecuteCommandListener = this._commandService.onDidExecuteCommand((command) => this.handleExecuteCommand(command)); + if (!this._onDidExecuteCommandListener) { + this._onDidExecuteCommandListener = this._commandService.onDidExecuteCommand(command => this._proxy.$handleDidExecuteCommand(command)); + } } $unregisterCommandListener() { - return this._onDidExecuteCommandListener.dispose(); + if (this._onDidExecuteCommandListener) { + this._onDidExecuteCommandListener.dispose(); + this._onDidExecuteCommandListener = undefined; + } } $getCommands(): Promise { return Promise.resolve(Object.keys(CommandsRegistry.getCommands())); } - - handleExecuteCommand(command: ICommandEvent) { - this._proxy.$handleDidExecuteCommand(command); - } } // --- command doc diff --git a/src/vs/workbench/api/common/extHostCommands.ts b/src/vs/workbench/api/common/extHostCommands.ts index 2c84c8d03f7..178834dad96 100644 --- a/src/vs/workbench/api/common/extHostCommands.ts +++ b/src/vs/workbench/api/common/extHostCommands.ts @@ -19,7 +19,6 @@ import { Range } from 'vs/editor/common/core/range'; import { Position } from 'vs/editor/common/core/position'; import { URI } from 'vs/base/common/uri'; import { Event, Emitter } from 'vs/base/common/event'; -import { IDisposable } from 'vs/base/common/lifecycle'; interface CommandHandler { callback: Function; @@ -32,8 +31,9 @@ export interface ArgumentProcessor { } export class ExtHostCommands implements ExtHostCommandsShape { - private readonly _onDidExecuteCommand: Emitter; - readonly onDidExecuteCommandEmitter: Event; + + private readonly _onDidExecuteCommand: Emitter; + readonly onDidExecuteCommand: Event; private readonly _commands = new Map(); private readonly _proxy: MainThreadCommandsShape; @@ -47,11 +47,11 @@ export class ExtHostCommands implements ExtHostCommandsShape { logService: ILogService ) { this._proxy = mainContext.getProxy(MainContext.MainThreadCommands); - this._onDidExecuteCommand = new Emitter({ + this._onDidExecuteCommand = new Emitter({ onFirstListenerDidAdd: () => this._proxy.$registerCommandListener(), onLastListenerRemove: () => this._proxy.$unregisterCommandListener(), }); - this.onDidExecuteCommandEmitter = this._onDidExecuteCommand.event; + this.onDidExecuteCommand = this._onDidExecuteCommand.event; this._logService = logService; this._converter = new CommandsConverter(this, heapService); this._argumentProcessors = [ @@ -116,12 +116,8 @@ export class ExtHostCommands implements ExtHostCommandsShape { }); } - onDidExecuteCommand(listener: (command: ICommandEvent) => any, thisArgs?: any, disposables?: IDisposable[]) { - return this.onDidExecuteCommandEmitter(listener, thisArgs, disposables); - } - $handleDidExecuteCommand(command: ICommandEvent): void { - this._onDidExecuteCommand.fire(command); + this._onDidExecuteCommand.fire({ command: command.commandId, arguments: command.args }); } executeCommand(id: string, ...args: any[]): Promise { @@ -172,7 +168,7 @@ export class ExtHostCommands implements ExtHostCommandsShape { try { const result = callback.apply(thisArg, args); - this._onDidExecuteCommand.fire({ commandId: id, args }); + this._onDidExecuteCommand.fire({ command: id, arguments: args }); return Promise.resolve(result); } catch (err) { this._logService.error(err, id); -- GitLab