Getting functions of all extensions

Is there a way where I can get all the functions for registered services/contributions with scope public like a library in extensions.

For example, to create new file, let’s say

@inject
private readonly library: TheiaExtensionLibrary;

somefunction () {
    this.library.fileService.createNewFile('/path/to/file');
}

Ideally, I would want this to happen by injecting one dependency which just keeps track of all installed extension and their public API’s.

[original thread by Karthik Bhat K]

Not out of the box, you could create such class if you want. Why do you want it? API discoverability?

[Karthik Bhat K]

Not out of the box, you could create such class if you want
Ideally, I don’t want to create a class. Reason: because then I have to maintain it.

Why do you want it?
For example, if I want to create a new file, the code for it is already written. It’s just that the fileSystem service is not injected. In my extension, i expect user to specify what service should be injected and what function of the service should be triggered.

[Karthik Bhat K]

This is already achieved in executeCommand of command-module

node_modules/@theia/core/src/common/command.ts

this.commands // will give me all the command, and
this.commandRegistry.executeCommand(commandId, ...commandOptions); // will execute the command based on the command Id

However, commands work only for Ctrl + Shift + P available commands. I want to be able to execute all the public function of each class.

You can create a js proxy around an instance of Container doing such things.

But i don’t know why someone would want to use such dynamic object, there won’t be any content assist and type checking at compile time.

[Karthik Bhat K]

Well that’s because if an external app wants to communicate with self hosted theia ide to send instructions it is required. That’s the use case I have.

I don’t think it is going to work for everything, only for services serving pure JSON objects. Usually we will build a statically typed facade with cleanly defined protocol.