Can commandRegistry.executeCommand return a value?

Hi all,

Could you please provide an example in theia where a command handler returns a value or object ?
i.e., the caller calls a command thru commandRegistry.executeCommand and can it use the return value?

@rs here’s an example:

Thank you very much, I shall try this.

1 Like

Hi all, @vince-fugnitto

I have a scenario in which I need to fetch the return value of a command that gets executed in a plugin’s backend:

In one of the extensions, there is a call to get the value returned by a command handler:

var testString = await this.commandReg.executeCommand('test.getTestString');

after the command gets executed, the value of testString is undefined !

Please refer to a plugin’s backend code that has the command handler:

export function start(context: theia.PluginContext) {

    const getTestString = {
        id: 'test.getTestString',
        label: "getTestString"
    };

    context.subscriptions.push(theia.commands.registerCommand(getTestString, async (...args: any[]): Promise<string> => {
        return Promise.resolve('HelloUrl');
    }));
}

It seems like i’m missing something (not sure how to use rpc to get the command to return the value).
Please help.

Are you sure that extenion is activated contributing a command is active at this moment? Try to list it onCommand:test.getTestString in activation events of VS Code extension.