Avoid registering api commands on the renderer

This commit is contained in:
Alex Dima
2018-03-21 12:25:11 +01:00
parent f9998f3590
commit 99b5cb6c9c
4 changed files with 17 additions and 12 deletions

View File

@@ -54,7 +54,7 @@ export class ExtHostCommands implements ExtHostCommandsShape {
this._argumentProcessors.push(processor);
}
registerCommand(id: string, callback: <T>(...args: any[]) => T | Thenable<T>, thisArg?: any, description?: ICommandHandlerDescription): extHostTypes.Disposable {
registerCommand(global: boolean, id: string, callback: <T>(...args: any[]) => T | Thenable<T>, thisArg?: any, description?: ICommandHandlerDescription): extHostTypes.Disposable {
this._logService.trace('ExtHostCommands#registerCommand', id);
if (!id.trim().length) {
@@ -66,11 +66,15 @@ export class ExtHostCommands implements ExtHostCommandsShape {
}
this._commands.set(id, { callback, thisArg, description });
this._proxy.$registerCommand(id);
if (global) {
this._proxy.$registerCommand(id);
}
return new extHostTypes.Disposable(() => {
if (this._commands.delete(id)) {
this._proxy.$unregisterCommand(id);
if (global) {
this._proxy.$unregisterCommand(id);
}
}
});
}
@@ -161,15 +165,16 @@ export class ExtHostCommands implements ExtHostCommandsShape {
export class CommandsConverter {
private readonly _delegatingCommandId: string;
private _commands: ExtHostCommands;
private _heap: ExtHostHeapService;
// --- conversion between internal and api commands
constructor(commands: ExtHostCommands, heap: ExtHostHeapService) {
this._delegatingCommandId = `_internal_command_delegation_${Date.now()}`;
this._commands = commands;
this._heap = heap;
this._commands.registerCommand('_internal_command_delegation', this._executeConvertedCommand, this);
this._commands.registerCommand(true, this._delegatingCommandId, this._executeConvertedCommand, this);
}
toInternal(command: vscode.Command): modes.Command {
@@ -190,7 +195,7 @@ export class CommandsConverter {
const id = this._heap.keep(command);
ObjectIdentifier.mixin(result, id);
result.id = '_internal_command_delegation';
result.id = this._delegatingCommandId;
result.arguments = [id];
}