diff --git a/packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts b/packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts index 0cf80713a5980..c2eabf61d49fd 100644 --- a/packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts +++ b/packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts @@ -39,21 +39,6 @@ export enum ExtensionKind { export const doInitialization: BackendInitializationFn = (apiFactory: PluginAPIFactory, plugin: Plugin) => { const vscode = Object.assign(apiFactory(plugin), { ExtensionKind }); - // replace command API as it will send only the ID as a string parameter - const registerCommand = vscode.commands.registerCommand; - vscode.commands.registerCommand = function (command: theia.CommandDescription | string, handler?: (...args: any[]) => T | Thenable, thisArg?: any): any { - // use of the ID when registering commands - if (typeof command === 'string') { - const rawCommands = plugin.rawModel.contributes && plugin.rawModel.contributes.commands; - const commands = rawCommands ? Array.isArray(rawCommands) ? rawCommands : [rawCommands] : undefined; - if (handler && commands && commands.some(item => item.command === command)) { - return vscode.commands.registerHandler(command, handler, thisArg); - } - return registerCommand({ id: command }, handler, thisArg); - } - return registerCommand(command, handler, thisArg); - }; - // use Theia plugin api instead vscode extensions (vscode).extensions = { get all(): any[] { diff --git a/packages/plugin-ext/src/plugin/plugin-context.ts b/packages/plugin-ext/src/plugin/plugin-context.ts index 2680682212acc..a32ec4c5ccfea 100644 --- a/packages/plugin-ext/src/plugin/plugin-context.ts +++ b/packages/plugin-ext/src/plugin/plugin-context.ts @@ -184,7 +184,16 @@ export function createAPIFactory( return function (plugin: InternalPlugin): typeof theia { const commands: typeof theia.commands = { // eslint-disable-next-line @typescript-eslint/no-explicit-any - registerCommand(command: theia.CommandDescription, handler?: (...args: any[]) => T | Thenable, thisArg?: any): Disposable { + registerCommand(command: theia.CommandDescription | string, handler?: (...args: any[]) => T | Thenable, thisArg?: any): Disposable { + // use of the ID when registering commands + if (typeof command === 'string') { + const rawCommands = plugin.rawModel.contributes && plugin.rawModel.contributes.commands; + const contributedCommands = rawCommands ? Array.isArray(rawCommands) ? rawCommands : [rawCommands] : undefined; + if (handler && contributedCommands && contributedCommands.some(item => item.command === command)) { + return commandRegistry.registerHandler(command, handler, thisArg); + } + return commandRegistry.registerCommand({ id: command }, handler, thisArg); + } return commandRegistry.registerCommand(command, handler, thisArg); }, // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index 6165fe32848e3..ad53344802561 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -2239,7 +2239,7 @@ declare module '@theia/plugin' { * * Throw if a command is already registered for the given command identifier. */ - export function registerCommand(command: CommandDescription, handler?: (...args: any[]) => any, thisArg?: any): Disposable; + export function registerCommand(command: CommandDescription | string, handler?: (...args: any[]) => any, thisArg?: any): Disposable; /** * Register the given handler for the given command identifier. @@ -9233,3 +9233,4 @@ declare module '@theia/plugin' { provideCallHierarchyOutgoingCalls(item: CallHierarchyItem, token: CancellationToken): ProviderResult; } } +