提交 fa406d2d 编写于 作者: J Johannes Rieken

tiny tweaks

上级 ab769475
......@@ -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<ICommandEvent>;
export const onDidExecuteCommand: Event<CommandExecutionEvent>;
}
//#endregion
......
......@@ -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<string, IDisposable>();
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<string[]> {
return Promise.resolve(Object.keys(CommandsRegistry.getCommands()));
}
handleExecuteCommand(command: ICommandEvent) {
this._proxy.$handleDidExecuteCommand(command);
}
}
// --- command doc
......
......@@ -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<ICommandEvent>;
readonly onDidExecuteCommandEmitter: Event<ICommandEvent>;
private readonly _onDidExecuteCommand: Emitter<vscode.CommandExecutionEvent>;
readonly onDidExecuteCommand: Event<vscode.CommandExecutionEvent>;
private readonly _commands = new Map<string, CommandHandler>();
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<ICommandEvent>({
this._onDidExecuteCommand = new Emitter<vscode.CommandExecutionEvent>({
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<T>(id: string, ...args: any[]): Promise<T> {
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册