How to use the @theia/plugin-ext.createAPI function in @theia/plugin-ext

To help you get started, we’ve selected a few @theia/plugin-ext examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / plugin-ext-vscode / src / node / plugin-vscode-init.ts View on Github external
export const doInitialization: BackendInitializationFn = (rpc: any, pluginMetadata: PluginMetadata) => {
    const module = require('module');
    const vscodeModuleName = 'vscode';
    const vscode = createAPI(rpc);

    // register the commands that are in the package.json file
    const contributes: any = pluginMetadata.source.contributes;
    if (contributes && contributes.commands) {
        contributes.commands.forEach((commandItem: any) => {
            vscode.commands.registerCommand({ id: commandItem.command, label: commandItem.title });
        });
    }

    // replace command API as it will send only the ID as a string parameter
    vscode.commands.registerCommand = function registerCommand(command: any, handler?: (...args: any[]) => T | Thenable): any {
        // use of the ID when registering commands
        if (typeof command === 'string' && handler) {
            return vscode.commands.registerHandler(command, handler);
        }
    };