mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
Avoid registering api commands on the renderer
This commit is contained in:
@@ -161,10 +161,10 @@ export function createApiFactory(
|
||||
// namespace: commands
|
||||
const commands: typeof vscode.commands = {
|
||||
registerCommand(id: string, command: <T>(...args: any[]) => T | Thenable<T>, thisArgs?: any): vscode.Disposable {
|
||||
return extHostCommands.registerCommand(id, command, thisArgs);
|
||||
return extHostCommands.registerCommand(true, id, command, thisArgs);
|
||||
},
|
||||
registerTextEditorCommand(id: string, callback: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => void, thisArg?: any): vscode.Disposable {
|
||||
return extHostCommands.registerCommand(id, (...args: any[]): any => {
|
||||
return extHostCommands.registerCommand(true, id, (...args: any[]): any => {
|
||||
let activeTextEditor = extHostEditors.getActiveTextEditor();
|
||||
if (!activeTextEditor) {
|
||||
console.warn('Cannot execute ' + id + ' because there is no active text editor.');
|
||||
@@ -185,7 +185,7 @@ export function createApiFactory(
|
||||
});
|
||||
},
|
||||
registerDiffInformationCommand: proposedApiFunction(extension, (id: string, callback: (diff: vscode.LineChange[], ...args: any[]) => any, thisArg?: any): vscode.Disposable => {
|
||||
return extHostCommands.registerCommand(id, async (...args: any[]) => {
|
||||
return extHostCommands.registerCommand(true, id, async (...args: any[]) => {
|
||||
let activeTextEditor = extHostEditors.getActiveTextEditor();
|
||||
if (!activeTextEditor) {
|
||||
console.warn('Cannot execute ' + id + ' because there is no active text editor.');
|
||||
|
||||
@@ -269,7 +269,7 @@ export class ExtHostApiCommands {
|
||||
// --- command impl
|
||||
|
||||
private _register(id: string, handler: (...args: any[]) => any, description?: ICommandHandlerDescription): void {
|
||||
let disposable = this._commands.registerCommand(id, handler, this, description);
|
||||
let disposable = this._commands.registerCommand(false, id, handler, this, description);
|
||||
this._disposables.push(disposable);
|
||||
}
|
||||
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user