Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7295 Theia API is incompatible with VSCode #7296

Merged
merged 1 commit into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?: <T>(...args: any[]) => T | Thenable<T>, 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
(<any>vscode).extensions = {
get all(): any[] {
Expand Down
11 changes: 10 additions & 1 deletion packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,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?: <T>(...args: any[]) => T | Thenable<T | undefined>, thisArg?: any): Disposable {
registerCommand(command: theia.CommandDescription | string, handler?: <T>(...args: any[]) => T | Thenable<T | undefined>, 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
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -9170,3 +9170,4 @@ declare module '@theia/plugin' {
provideCallHierarchyOutgoingCalls(item: CallHierarchyItem, token: CancellationToken): ProviderResult<CallHierarchyOutgoingCall[]>;
}
}